From owner-svn-src-all@freebsd.org Sun Sep 2 18:29:39 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C1C25FF5ED4; Sun, 2 Sep 2018 18:29:39 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7B181825B1; Sun, 2 Sep 2018 18:29:39 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5BF151CE87; Sun, 2 Sep 2018 18:29:39 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w82ITdxi047688; Sun, 2 Sep 2018 18:29:39 GMT (envelope-from alc@FreeBSD.org) Received: (from alc@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w82ITdvi047687; Sun, 2 Sep 2018 18:29:39 GMT (envelope-from alc@FreeBSD.org) Message-Id: <201809021829.w82ITdvi047687@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alc set sender to alc@FreeBSD.org using -f From: Alan Cox Date: Sun, 2 Sep 2018 18:29:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338431 - head/sys/vm X-SVN-Group: head X-SVN-Commit-Author: alc X-SVN-Commit-Paths: head/sys/vm X-SVN-Commit-Revision: 338431 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Sep 2018 18:29:39 -0000 Author: alc Date: Sun Sep 2 18:29:38 2018 New Revision: 338431 URL: https://svnweb.freebsd.org/changeset/base/338431 Log: Recent changes have created, for the first time, physical memory segments that can be coalesced. To be clear, fragmentation of phys_avail[] is not the cause. This fragmentation of vm_phys_segs[] arises from the "special" calls to vm_phys_add_seg(), in other words, not those that derive directly from phys_avail[], but those that we create for the initial kernel page table pages and now for the kernel and modules loaded at boot time. Since we sometimes iterate over the physical memory segments, coalescing these segments at initialization time is a worthwhile change. Reviewed by: kib, markj Approved by: re (rgrimes) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D16976 Modified: head/sys/vm/vm_phys.c Modified: head/sys/vm/vm_phys.c ============================================================================== --- head/sys/vm/vm_phys.c Sun Sep 2 17:02:13 2018 (r338430) +++ head/sys/vm/vm_phys.c Sun Sep 2 18:29:38 2018 (r338431) @@ -460,7 +460,7 @@ void vm_phys_init(void) { struct vm_freelist *fl; - struct vm_phys_seg *seg; + struct vm_phys_seg *end_seg, *prev_seg, *seg, *tmp_seg; u_long npages; int dom, flind, freelist, oind, pind, segind; @@ -544,6 +544,29 @@ vm_phys_init(void) ("vm_phys_init: DEFAULT flind < 0")); } seg->free_queues = &vm_phys_free_queues[seg->domain][flind]; + } + + /* + * Coalesce physical memory segments that are contiguous and share the + * same per-domain free queues. + */ + prev_seg = vm_phys_segs; + seg = &vm_phys_segs[1]; + end_seg = &vm_phys_segs[vm_phys_nsegs]; + while (seg < end_seg) { + if (prev_seg->end == seg->start && + prev_seg->free_queues == seg->free_queues) { + prev_seg->end = seg->end; + KASSERT(prev_seg->domain == seg->domain, + ("vm_phys_init: free queues cannot span domains")); + vm_phys_nsegs--; + end_seg--; + for (tmp_seg = seg; tmp_seg < end_seg; tmp_seg++) + *tmp_seg = *(tmp_seg + 1); + } else { + prev_seg = seg; + seg++; + } } /*