From patchwork Tue Dec 10 02:41:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 13900737 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B72D1A01C5 for ; Tue, 10 Dec 2024 02:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733798488; cv=none; b=qvAJK8XH9xTMgwgp5fKPDX27dFwgOH66fYPXaHU4g71TAiil4X+SY1CjGxO/Y81MnXYZzsZZmm8FGR389czLWd6c76TQBrHQm0gUjDSDoFUslfca8S81zSkIHRfNncq4r5gUo2Ftt8Z8R8AUAcVjgKX+XMn+IxtFOEKCsgLhqeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733798488; c=relaxed/simple; bh=mpvxmscjVgbLdO7cK/zBkRD+gPYja4DIS+1NwMw48+c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aS85mtaj7A7Pkss6rnJ+JySOKal1mJ1pXSwOL1YLXR2OCjtf5E4MdVagaSwqUB6uar8KLuPy5Nb6vsLpULjhWlFpKoO9EwwKM8Y09J3ZqwOtU0Lp0OUw9UIEdvA/pTbWNb79gGbI3FPNDaiFzSRW+mYgFi0muJ0FvMHnPhscFj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Xkfmh4b1; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kaleshsingh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xkfmh4b1" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7fb966ee0cdso3579478a12.1 for ; Mon, 09 Dec 2024 18:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733798485; x=1734403285; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nXKIsvWsBBTYmcaRz8JoUa2+7Qpfg8xMl3r7PMmLvBk=; b=Xkfmh4b1HMhS6EeVnOfmT4VtEykAz9/o9O3C8yXC65ttVozCZ1R5Sdm2wHW35ssCCq QaStk5pi9SgHr0Z5QgzaP6s+HnyI7lNwuSl9b/wGQ53Pi7mud9Z2C88R4Yb4K7Uj/R6R p9FQr6WLVL/Lpl6/fWWpNiAlCxa2WFG9oVOZoF8+uuw2UL72BdbelcyOC1mcrzx/RNNu chGebqPASiRlDZ5i2ECCBSfvMGZyf7Y2+v71RDRZSdfx4m4TQlWQAIDn6nbbEDnsQonJ uHTKtjH2AFE3AD3WMiarsi9YLRhXv6vcX6DAxFNXOOsgCbAh+bgQgZZer/YypWKjgFK0 sJLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733798486; x=1734403286; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nXKIsvWsBBTYmcaRz8JoUa2+7Qpfg8xMl3r7PMmLvBk=; b=u5PCRWfYZbwsLEhq6GFUsqE1RDz8H++jXaojZ8xu2fljJiU3Lo+rBJG3dIygmjrxjl whzGbKkbkOw3tHg/3YLefr0m/1tYihgwZlpDidQEQKrEWj1TJVg7SlZjR33ju8HovjFy jpfKVQ03Ihpuhl0HIKahV+pg0yDRRMgfe1Cr/88ukEGqIeyCMJPv3q9WqQhnWKHqgKmv ZDbeyzvMADMTp+yBPahEyZCcj+n14YSDyg82iNfZrPcNGlqAH4WsyvjuwAyWGoq3iCKz m96kXs387bXSZo9UPkxJ19MOV7BQj4ZOXdPrLCOAt2ijzO5FDqsMyYnZV7xgSfLLZynQ pdtA== X-Forwarded-Encrypted: i=1; AJvYcCX5BiXZCnTppSKZsfHir7StDpiJNhml7SBH//2e/3qfisXPnwzTpnV/nsA/kibIl8rGBqlEV6aecg==@vger.kernel.org X-Gm-Message-State: AOJu0YyX+Y62y4HJmSNcYf8NjFi1halE3/GYju39/S18NtCEkYjXO0Wn E4vJH7SkkuG8WGHMDNB9pnprCPV/eOeZR8wzjbCFvy6r543RVI3JMZV5DgXjtP6Vsx6Gly49Mkv LCGE66AGv0Up6cOiU/W0yDw== X-Google-Smtp-Source: AGHT+IEes4vFC8x7oz2PD6CyRh4s+tzg2fdn8MPTeQEnOJJBB4JDPOzOCc3jB91eMpzo0BdpMiIRvdYY+YmWIeDh+w== X-Received: from pfau15.prod.google.com ([2002:a05:6a00:aa8f:b0:728:2357:646a]) (user=kaleshsingh job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7483:b0:1e1:adb8:c011 with SMTP id adf61e73a8af0-1e1b4435999mr2770722637.18.1733798485628; Mon, 09 Dec 2024 18:41:25 -0800 (PST) Date: Mon, 9 Dec 2024 18:41:03 -0800 In-Reply-To: <20241210024119.2488608-1-kaleshsingh@google.com> Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241210024119.2488608-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241210024119.2488608-2-kaleshsingh@google.com> Subject: [PATCH mm-unstable 01/17] mm: Introduce generic_mmap_hint() From: Kalesh Singh To: akpm@linux-foundation.org, vbabka@suse.cz, yang@os.amperecomputing.com, riel@surriel.com, david@redhat.com Cc: linux@armlinux.org.uk, tsbogend@alpha.franken.de, James.Bottomley@HansenPartnership.com, ysato@users.sourceforge.jp, dalias@libc.org, glaubitz@physik.fu-berlin.de, davem@davemloft.net, andreas@gaisler.com, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chris@zankel.net, jcmvbkbc@gmail.com, bhelgaas@google.com, jason.andryuk@amd.com, leitao@debian.org, linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-mm@kvack.org, kernel-team@android.com, android-mm@google.com, Kalesh Singh Consolidate the hint searches from both direcitons (topdown and bottomup) into generic_mmap_hint(). No functional change is introduced. Signed-off-by: Kalesh Singh --- include/linux/sched/mm.h | 4 ++++ mm/mmap.c | 45 ++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h index 928a626725e6..edeec19d1708 100644 --- a/include/linux/sched/mm.h +++ b/include/linux/sched/mm.h @@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmflags(struct mm_struct *mm, unsigned long flags, vm_flags_t vm_flags); +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); + unsigned long generic_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, diff --git a/mm/mmap.c b/mm/mmap.c index df9154b15ef9..e97eb8bf4889 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -620,6 +620,27 @@ unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info) return addr; } +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma, *prev; + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + + if (!addr) + return 0; + + addr = PAGE_ALIGN(addr); + vma = find_vma_prev(mm, addr, &prev); + if (mmap_end - len >= addr && addr >= mmap_min_addr && + (!vma || addr + len <= vm_start_gap(vma)) && + (!prev || addr >= vm_end_gap(prev))) + return addr; + + return 0; +} + /* Get an address range which is currently unmapped. * For shmat() with addr=0. * @@ -637,7 +658,6 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma, *prev; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); @@ -647,14 +667,9 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, if (flags & MAP_FIXED) return addr; - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.length = len; info.low_limit = mm->mmap_base; @@ -685,7 +700,6 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma, *prev; struct mm_struct *mm = current->mm; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); @@ -698,14 +712,9 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, return addr; /* requesting a specific address */ - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len;