From nobody Sat May 18 05:34:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647403581759484.50188008467364; Tue, 15 Mar 2022 21:06:21 -0700 (PDT) Received: from localhost ([::1]:54652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUKvU-0005Te-5M for importer@patchew.org; Wed, 16 Mar 2022 00:06:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUKu8-0004lK-Ll for qemu-devel@nongnu.org; Wed, 16 Mar 2022 00:04:58 -0400 Received: from smtp116.iad3a.emailsrvr.com ([173.203.187.116]:47135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUKu6-00077z-Oz for qemu-devel@nongnu.org; Wed, 16 Mar 2022 00:04:56 -0400 Received: by smtp39.relay.iad3a.emailsrvr.com (Authenticated sender: adeason-AT-sinenomine.net) with ESMTPSA id 4A8DE4325; Wed, 16 Mar 2022 00:04:51 -0400 (EDT) X-Auth-ID: adeason@sinenomine.net From: Andrew Deason To: qemu-devel@nongnu.org Subject: [PATCH] softmmu/physmem: Use qemu_madvise Date: Tue, 15 Mar 2022 23:04:05 -0500 Message-Id: <20220316040405.4131-1-adeason@sinenomine.net> X-Mailer: git-send-email 2.11.0 X-Classification-ID: 0d3ca5e0-ac42-4b96-9df2-d16d0103ead4-1-1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=173.203.187.116; envelope-from=adeason@sinenomine.net; helo=smtp116.iad3a.emailsrvr.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Xu , "Dr . David Alan Gilbert" , Andrew Deason , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1647403583649100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have a thin wrapper around madvise, called qemu_madvise, which provides consistent behavior for the !CONFIG_MADVISE case, and works around some platform-specific quirks (some platforms only provide posix_madvise, and some don't offer all 'advise' types). This specific caller of madvise has never used it, tracing back to its original introduction in commit e0b266f01dd2 ("migration_completion: Take current state"). Call qemu_madvise here, to follow the same logic as all of our other madvise callers. This slightly changes the behavior for !CONFIG_MADVISE (EINVAL instead of ENOSYS, and a slightly different error message), but this is now more consistent with other callers that use qemu_madvise. Signed-off-by: Andrew Deason --- Looking at the history of commits that touch this madvise() call, it doesn't _look_ like there's any reason to be directly calling madvise vs qemu_advise (I don't see anything mentioned), but I'm not sure. softmmu/physmem.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 43ae70fbe2..900c692b5e 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3584,40 +3584,32 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t = start, size_t length) rb->idstr, start, length, ret); goto err; #endif } if (need_madvise) { /* For normal RAM this causes it to be unmapped, * for shared memory it causes the local mapping to disappear * and to fall back on the file contents (which we just * fallocate'd away). */ -#if defined(CONFIG_MADVISE) if (qemu_ram_is_shared(rb) && rb->fd < 0) { - ret =3D madvise(host_startaddr, length, QEMU_MADV_REMOVE); + ret =3D qemu_madvise(host_startaddr, length, QEMU_MADV_REM= OVE); } else { - ret =3D madvise(host_startaddr, length, QEMU_MADV_DONTNEED= ); + ret =3D qemu_madvise(host_startaddr, length, QEMU_MADV_DON= TNEED); } if (ret) { ret =3D -errno; error_report("ram_block_discard_range: Failed to discard r= ange " "%s:%" PRIx64 " +%zx (%d)", rb->idstr, start, length, ret); goto err; } -#else - ret =3D -ENOSYS; - error_report("ram_block_discard_range: MADVISE not available" - "%s:%" PRIx64 " +%zx (%d)", - rb->idstr, start, length, ret); - goto err; -#endif } trace_ram_block_discard_range(rb->idstr, host_startaddr, length, need_madvise, need_fallocate, ret); } else { error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu= 64 "/%zx/" RAM_ADDR_FMT")", rb->idstr, start, length, rb->max_length); } =20 err: --=20 2.11.0