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: 13900676 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 6025B1A071C for ; Tue, 10 Dec 2024 02:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733798488; cv=none; b=hsO0zGJOiO1AlkY90NTmGUc/GaPYcuBuQ33oGqSuJh7PDu5z3GraHi+scvHR8EwjddfIAz0r4JXawOKaOFVzAsDyMADgc+N2Zc/+oorWsIGiaA2ffG4IdFCFg89sQGyBPT7UxcDqWSQbioZw3tOKAQ1V/BOUhE/Rgj2db7v+CO8= 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=RO3MhUgo; arc=none smtp.client-ip=209.85.215.202 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="RO3MhUgo" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7fd5777a6aaso708122a12.0 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=1733798486; x=1734403286; 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=RO3MhUgoR5UKfJbZrNhAamwAxSNLn400l5sVDkmIx7KrADm+xT+F7EcjyrYktCWnJk CBjVZrA5YI/HW/Dwlzzotd8ot5dtVMIxR2IIkh+huII2ClRZ9EfsF1MaoUxSX6Vk5xu+ /g5OZdj3oMFhSIQ1jtWKB+C7wXU/nBYobQUyhGoEDpRs/dr7E95mPqE/wJiuIcFRjv7c 9rtR2bPVjedeUBimzBBvhK5mQpmJy9NNhNpa0D4+bXpPXsfwjk7bCmDzsqnXWyEULJfg dv66lD8MeLoQZetunNloBBBwcXSmmxtcMaK9XJ9RR6NzXPldlp113tmd4PqZ16iXZqMS wuBQ== 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=rTHZNxRGprPVqq2LPMBVbYbVUUFs5adpPpyhQE9J3bdyGj78GedoV3l4KCg61bNLNn JB8YfKO72oRM8FBKyly3wrI7SNfJCyNwfBFvqoZ1INQUQD1SM63mQQX4QGUL6FrN2+QL LyLfSKP52JPgvtaKVQmCt5m20f6apN3Z1azzVzKVcTbAuz8PIY2YGcantBlXp/ui9uSW xvajazk1QGu4RhRiwShb/pLvCp7KjtVMhIi7ZhQmWIN6/v59uyx9y25zwrGJEQIMCsH3 ynuiQrrGXM5uGDf5DAf1bxXcLH0ET9zLFMQi1BVUzIQ9Z4mLZzpS9f024I9Cx1evbYV9 R92A== X-Forwarded-Encrypted: i=1; AJvYcCX7zKj+jzY4tl06WAMcB9JKRH5LCfgquT2zwl23KN5V5JllpVgE1YTiuL0/JPr40xLdFr0efJ9QWA56@vger.kernel.org X-Gm-Message-State: AOJu0YyVON5lTJrW2Soy1h7ZFpjzlFXnmV0lgfKGw6AI3t6YJDDS4bGb n3S3DLkvKXKVDOBO7+QtR5a12QJN5Wq6acIdgQZM4fG2Z9vtnV0fFjhhLOYB+zHzquVBa1PO6GW t1yYJn65m34TM9ANqbshi2Q== 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-mips@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;