From nobody Sat Aug 5 02:11:37 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RHmKj2RCwz4mQls; Sat, 5 Aug 2023 02:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RHmKj20bKz3cYQ; Sat, 5 Aug 2023 02:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691201497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aK1Uka0suiNT5e3VkAmczeQhrxFPmmSGj13RbMG0eTM=; b=d1zYa9P/HVmlT3uiicZd99EbsI6hfoLG//weA4h5enzzHEigy1fzwU/hDG8T6fk7X+b4NZ zfVYPbtwip6KCMUKej3exK6H8BA34kI7wqE0xVZ4pt3w3pWkbU+AVAvLv8Ih24uu+8LlQU HflmG5QG7gZJlzM+O/d5ljsiU3MLulwmLj7xTMXDcf7xtLOwJjy3DYQywW5ukUDfaviZAc 6lDKeKFcEXLzM8U2JFgT8oGudyyXHGDYVlcVqdRxORvzkxnGcgvPx0gVY9M184XqdevUsf +hXoR+Dl6CMEsfo4KeNQGto8YoN1Ih+uI+4kfRGFDnzSUqZoxzYxV/GjQ/9ndw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691201497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aK1Uka0suiNT5e3VkAmczeQhrxFPmmSGj13RbMG0eTM=; b=t23xO0ijs2FpqROQ4UHZ+qBpFpgtjq12nWoLrsb+zgf/FdhE5mmul3nJxmFYc4aCT5uROl GnP8LzMmkq2ey0ItixGmqI+oVND/I4R8en+9MdeurV9Kk8hV1jixV/EItbW2tOZZbOlo8t C5mQ10vCjUt1axpLY81j7j041V1YS0YmCrApdlQDdopXjaCDJT0Rls5txB6JXNN4AbkE/V AzYLrd0IpOpJTCwX71NpoJxxZcLiVOo0lMQWWqgRD8MQNBuCdMA/WoUnRX0Jlv8ZA4X+cW 3wU3vorCqgaCuGFnb4mEBsHybTjhCE/ajbM552KiJWmir5Zi4uapGpx3nlzt1g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691201497; a=rsa-sha256; cv=none; b=UH+nHOM8I4Vb/lsKLXj3hmK/Emq8pr7y+lV3oGtnLPhq4HsQ/CceeHnqfeWjXsZkFfpZ8d YKW6veuZhOuWG4QeGHzMZk+mSWPp5PmDT6xTlHomld/0Ui31lHbgXB/l2xwOU1NEoAIn2B +c6iEd57AsI35wQSH4cQUUSsGRcrt03Tbpr2QIik42W2H8jnAlAsNoWMLytapZ6mH22XDp nMUZZMSTBMgjPeILHnU+7mTprPPCEGizY4YUlVI/NNt/GAj/nhJv28ATop8vheBOAdPm8D 4TMs0szedHsn9wo3GpDoWhSxgY5VKERFOipKLytsl6RkdVRk+VBrbOqmFWttnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RHmKj13Lpz1PvM; Sat, 5 Aug 2023 02:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3752BbCv004018; Sat, 5 Aug 2023 02:11:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3752Bb1I004017; Sat, 5 Aug 2023 02:11:37 GMT (envelope-from git) Date: Sat, 5 Aug 2023 02:11:37 GMT Message-Id: <202308050211.3752Bb1I004017@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: e77f4e7f5972 - main - vm_phys: tune vm_phys_enqueue_contig loop List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e77f4e7f597261bc873227a0dfc05d178c367727 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=e77f4e7f597261bc873227a0dfc05d178c367727 commit e77f4e7f597261bc873227a0dfc05d178c367727 Author: Doug Moore AuthorDate: 2023-08-05 02:09:39 +0000 Commit: Doug Moore CommitDate: 2023-08-05 02:09:39 +0000 vm_phys: tune vm_phys_enqueue_contig loop Rewrite the final loop in vm_phys_enqueue_contig as a new function, vm_phys_enq_beg, to reduce amd64 code size. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D41289 --- sys/vm/vm_phys.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c index a3af3964fba4..bc9db6559bfe 100644 --- a/sys/vm/vm_phys.c +++ b/sys/vm/vm_phys.c @@ -680,6 +680,41 @@ vm_phys_split_pages(vm_page_t m, int oind, struct vm_freelist *fl, int order, } } +/* + * Add the physical pages [m, m + npages) at the beginning of a power-of-two + * aligned and sized set to the specified free list. + * + * When this function is called by a page allocation function, the caller + * should request insertion at the head unless the lower-order queues are + * known to be empty. The objective being to reduce the likelihood of long- + * term fragmentation by promoting contemporaneous allocation and (hopefully) + * deallocation. + * + * The physical page m's buddy must not be free. + */ +static void +vm_phys_enq_beg(vm_page_t m, u_int npages, struct vm_freelist *fl, int tail) +{ + int order; + + KASSERT(npages == 0 || + (VM_PAGE_TO_PHYS(m) & + ((PAGE_SIZE << (fls(npages) - 1)) - 1)) == 0, + ("%s: page %p and npages %u are misaligned", + __func__, m, npages)); + while (npages > 0) { + KASSERT(m->order == VM_NFREEORDER, + ("%s: page %p has unexpected order %d", + __func__, m, m->order)); + order = fls(npages) - 1; + KASSERT(order < VM_NFREEORDER, + ("%s: order %d is out of range", __func__, order)); + vm_freelist_add(fl, m, order, tail); + m += 1 << order; + npages -= 1 << order; + } +} + /* * Add the physical pages [m, m + npages) at the end of a power-of-two aligned * and sized set to the specified free list. @@ -1190,14 +1225,7 @@ vm_phys_enqueue_contig(vm_page_t m, u_long npages) m += 1 << order; } /* Free blocks of diminishing size. */ - while (m < m_end) { - KASSERT(seg == &vm_phys_segs[m->segind], - ("%s: page range [%p,%p) spans multiple segments", - __func__, m_end - npages, m)); - order = flsl(m_end - m) - 1; - vm_freelist_add(fl, m, order, 1); - m += 1 << order; - } + vm_phys_enq_beg(m, m_end - m, fl, 1); } /*