Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2197399rdb; Tue, 20 Feb 2024 23:11:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX4YjadV/FKn4Tob0jPvWXlICCi/BVxGDVDdijQNwLEly+gUrptreYpyGLX1YJMfM20idyrMV5v/fOv/0P7VeA4NXqwFJkN/Bt7nSKEGg== X-Google-Smtp-Source: AGHT+IFQj16gWa3XP6LVo1DYdnVw/w/oFZp5XLDZW6B0EVa7vh6IIId9GVXA77QgV4egnlhdfzPW X-Received: by 2002:ac8:5d8b:0:b0:42c:721c:16fc with SMTP id d11-20020ac85d8b000000b0042c721c16fcmr31932233qtx.26.1708499468880; Tue, 20 Feb 2024 23:11:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708499468; cv=pass; d=google.com; s=arc-20160816; b=cY4vP5h1b0BiTevfq2YCWl9wcFDKW2hP10DzKWGSUnETCGIF7TJWpLzRSUKPDCLpPe 8Vs0lVhFmHb1agUqNvFqBILPuOkXWF3BvoyJ2E6c+oKesj12zoteYHRnxM7BClhy5XAz 6HFaia/ghEpEEDHGpLrbpMHc3K/ExIe0O8//bEzCl17NUufm897nKtbUxfS5tqU/Yod8 CgKreawLN3eCkhAgHGEgY584nLZevv91UOYb2+VTppUfPqZ47/KSJgERP2LGCkIRpbYp bdYhch9FThC80YmoFbwX5hTrUdBJ1oWtx13zBte9Ps7XNhAhqFH4nmqKEJ6k15Nw4v6q /1bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VOlrYMmoEpRW+NdqInqmdntxj7aJK+0IpKZ0inMtZCk=; fh=ED8b6jgMhbWC0m9a2XHoaZ3OwBpnDYDiOaZyL3naXmU=; b=C/7XIn9PvyiE5uorHNVIt82nhZKcRjw+ovJBGO++lOxmXoH0skb34c6cWQpyW7ObeV wxfMZg6aP6Z3qFoeYmGWW6y1GVbFl98N9rs38/5mQMpvdEZno5gz1dsPcbBXM25aQX+3 04wtp3iwo9y0A3Q/6lzRkDmdP9Q+cxiYC5kBdI9GkR6fR8dHpdxZT8lCbkDHglXbpIq7 F/J3n4jJH6O1n5PsKYOoaAD3rvMsJVvgUgZkXegDrXotbZ/+r4dBqZyZwr94mHNTiieD cU4fVv3szrTA/CE04ZfwfB0I1dhAGzbEUi6mI2WYUH7vtsuy76d75K9n5JfIMU2EBARh +zhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SVI+m3TR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x19-20020ac85393000000b0042c6d930f8csi9725169qtp.382.2024.02.20.23.11.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 23:11:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SVI+m3TR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-74192-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74192-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 332B61C23692 for ; Wed, 21 Feb 2024 07:10:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1B313A27B; Wed, 21 Feb 2024 07:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SVI+m3TR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAD539AF1 for ; Wed, 21 Feb 2024 07:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499439; cv=none; b=C/742LTtqd9KDNrRG7agwL0ybn3UrTM21g7NusEGXaW7P1LkP/gxiltrNYaLLM09NJlu9iHZ3+G/HTJzLTNAA/PPmXzHsQCc9UZr0/78kd2RfDAqCK60gEFsDgu/RHYegeMuxXD/Z4ORwHaZvm6KI2U9JlVELE6qwm8/1eqxVTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708499439; c=relaxed/simple; bh=A+d6DunIrChPzyLKEwkHG4SMJU+8ZOEePbqT/034MOg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AoCF2kCUM/3Sfi2+Zh9OCW6d82hrxblVYY9rfzOF9aE9ERigmdrZDA26b5/HydAGoGovwtz/Gp+YS71RFlRCOIsKoQ1MHuOHmEZitg54bq+kUjcyLmrr385C5G/5lKqGjxR36Nc489OkeyOhyWWDzWCCzuV+gSLZyWL/K0rBBGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SVI+m3TR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2042C433F1; Wed, 21 Feb 2024 07:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708499439; bh=A+d6DunIrChPzyLKEwkHG4SMJU+8ZOEePbqT/034MOg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SVI+m3TRr9NZeiwKeQU+Je9+cyUMD7o4+u25WNFyM8EfHG6wE/PR1+OKIXjoFamMz 9kKnpafi5tsUeaxG+fEscpdoTOmK+6kYgcIDQfIeQquQgDPLOEkwAiDq8yevqlucsG 9BkboSvAtkQj0iDqe1YsbII0eh1IQIMNmYxQmXncNC96+OFeoTPDaRIrvm+a4/DARd WGOR/LXPDR7lRCjeHl1770zJep5xa3WNsM5XxGls6h4Dhsz02BbRvfM9LhpE8BOhNW qG4LNXFnNckMsjkpGo30HJsP1z5BxdP6gU4CpH/Ta1jGxBn72QzgtLSlPKrsKw9mvh IpTqG7pAYkXKQ== Date: Wed, 21 Feb 2024 09:10:02 +0200 From: Mike Rapoport To: Rick Edgecombe Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org, debug@rivosinc.com, broonie@kernel.org, kirill.shutemov@linux.intel.com, keescook@chromium.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, luto@kernel.org, peterz@infradead.org, hpa@zytor.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 1/8] mm: Switch mm->get_unmapped_area() to a flag Message-ID: References: <20240215231332.1556787-1-rick.p.edgecombe@intel.com> <20240215231332.1556787-2-rick.p.edgecombe@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240215231332.1556787-2-rick.p.edgecombe@intel.com> On Thu, Feb 15, 2024 at 03:13:25PM -0800, Rick Edgecombe wrote: > The mm_struct contains a function pointer *get_unmapped_area(), which > is set to either arch_get_unmapped_area() or > arch_get_unmapped_area_topdown() during the initialization of the mm. > > Since the function pointer only ever points to two functions that are named > the same across all arch's, a function pointer is not really required. In > addition future changes will want to add versions of the functions that > take additional arguments. So to save a pointers worth of bytes in > mm_struct, and prevent adding additional function pointers to mm_struct in > future changes, remove it and keep the information about which > get_unmapped_area() to use in a flag. > > Introduce a helper, mm_get_unmapped_area(), to easily convert code that > refers to the old function pointer to instead select and call either > arch_get_unmapped_area() or arch_get_unmapped_area_topdown() based on the > flag. Then drop the mm->get_unmapped_area() function pointer. Leave the > get_unmapped_area() pointer in struct file_operations alone. The main > purpose of this change is to reorganize in preparation for future changes, > but it also converts the calls of mm->get_unmapped_area() from indirect > branches into a direct ones. > > The stress-ng bigheap benchmark calls realloc a lot, which calls through > get_unmapped_area() in the kernel. On x86, the change yielded a ~4% > improvement there. (bogo ops/s (usr+sys time)) > > In testing a few x86 configs, removing the pointer unfortunately didn't > result in any actual size reductions in the compiled layout of mm_struct. > But depending on compiler or arch alignment requirements, the change could > possibly shrink the size of mm_struct. > > Signed-off-by: Rick Edgecombe > --- > arch/s390/mm/hugetlbpage.c | 2 +- > arch/s390/mm/mmap.c | 4 ++-- > arch/sparc/kernel/sys_sparc_64.c | 15 ++++++--------- > arch/sparc/mm/hugetlbpage.c | 2 +- > arch/x86/kernel/cpu/sgx/driver.c | 2 +- > arch/x86/mm/hugetlbpage.c | 2 +- > arch/x86/mm/mmap.c | 4 ++-- > drivers/char/mem.c | 2 +- > drivers/dax/device.c | 6 +++--- > fs/hugetlbfs/inode.c | 2 +- > fs/proc/inode.c | 15 ++++++++------- > fs/ramfs/file-mmu.c | 2 +- > include/linux/mm_types.h | 6 +----- > include/linux/sched/coredump.h | 1 + > include/linux/sched/mm.h | 5 +++++ > io_uring/io_uring.c | 2 +- > mm/debug.c | 6 ------ > mm/huge_memory.c | 6 +++--- > mm/mmap.c | 21 ++++++++++++++++++--- > mm/shmem.c | 11 +++++------ > mm/util.c | 6 +++--- > 21 files changed, 65 insertions(+), 57 deletions(-) > > diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h > index 02f5090ffea2..428e440424c5 100644 > --- a/include/linux/sched/coredump.h > +++ b/include/linux/sched/coredump.h > @@ -74,6 +74,7 @@ static inline int get_dumpable(struct mm_struct *mm) > #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) > #define MMF_OOM_REAP_QUEUED 25 /* mm was queued for oom_reaper */ > #define MMF_MULTIPROCESS 26 /* mm is shared between processes */ > +#define MMF_TOPDOWN 27 /* mm is shared between processes */ Nit: you may want to update the comment here ;-) > /* > * MMF_HAS_PINNED: Whether this mm has pinned any pages. This can be either > * replaced in the future by mm.pinned_vm when it becomes stable, or grow into -- Sincerely yours, Mike.