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: 13900755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A27CFE7717D for ; Tue, 10 Dec 2024 02:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nXKIsvWsBBTYmcaRz8JoUa2+7Qpfg8xMl3r7PMmLvBk=; b=IorHZQ+CLKfoHvuvwExOBmRjj4 GvsScHM8RHsXMZ1i85V4QWUoCXLSWwF0B1H7AxF2C0Y2O+/X4udxH5VwHZFT0Z45uEjKZPdflCCuY EwymcAnG4x0p50jrOVfXKFv0oj/PvLLUDeFRS+pe2aIxVdtyarzdPrHqkVC3d5AANLOMZnk3EXK43 YKiMtrYYiA0lhibl6gPQCDdFQcjvdAw/b6b0h/GcgVeHKb0p1+CxEu1EoAzFZm6C9+BniWmojNYTf Osn7heJ1NZAzY+jDDS6MXLz7J8xY+iIirGIFkogTuKtTuM1FIt4LE5zxhwE1/3dWQUMsHEDPojds+ Zon3GOfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tKqDn-0000000A0dp-20ez; Tue, 10 Dec 2024 02:43:35 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tKqBj-00000009zW3-0ZEj for linux-arm-kernel@lists.infradead.org; Tue, 10 Dec 2024 02:41:28 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7fd5777a6aaso708121a12.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=lists.infradead.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=nx9q3YpgDjHi0rQ61LBEUc30If4zoNQi3SxF/7TzbkTycH4DfsNDJjURxTtjTzJFuW 5ko6cDFj8gp65kIeUA0UzZ8dtqSi/Wziry/slJmLXUBNrcz1qjsE3PDQFhOmgZP8qJIE J+HSgvSOZPKUzLmmZLbtpEOB6kH/x/g7rR7lI89D/7v9WNduEnaBeRayePGNcC2wRg4f lGaq3yziU1TqVfhhgHUPvCCZ8UvOxeyvuStAvtlLZqWWeX7mKHmwE3d+ojpCaj60yHb+ ulF7gWpQVLFP46qBKC2n7RstJw05pIjvKqeQhMdmppJ6v8iXaoKFyH+yy9uV5wVZsBpE fD0A== 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=JwJbyuq1wmRQGBYWwe6Bu3HEVv15XxUMn5G5FVJcOfYtaIJmAoRenCRcslDCT81BdD qmtgn9psjQ7IOTkpEozaj2CWG3DACHf+iu/cuePRk1l1KARVkFM0O8skpgOWC5YzJJdW JVDkIaLJWauZNsYzdIbPpsa/DIZInlgzlYCj/mK1CS1/DGYdc2lotwbN4FW5jwUB2tgZ VnGMNZEDaWI936xEH8d8ZMXnGx99OkXhbsjrSsZlcOl+LfeJYhOcdZ8xJjGzOx7qoAk1 1kbRnNBIw35mMmsJD+AFCJuPEb3/V7NNX7TlkZ3yjit58h9TVXpOyej+3KY9IGA6ERCe qeDw== X-Forwarded-Encrypted: i=1; AJvYcCVRWxglY5OoSAaLzHV1TGWqtwNGAevs0UTFPfmfUNDIZG8m9dybs7MPq5fuw1UGSKw6kN0cn6h4XYV6wqtNkV4t@lists.infradead.org X-Gm-Message-State: AOJu0YxuZxTznpLLssnZgRPcTNEKace34oF6K4zh9oxrM69UmB3cFTzp MtfRxg7a4wNJ7MTAPNCtGW5XHhDQeA1BsDegT9cRFFeqoWWliFuo7TBIGRBvP2en10iJYVyJQtt DMVGrd2l7xGKiEpIa+L/5NQ== 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> 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241209_184127_165937_CBF271F2 X-CRM114-Status: GOOD ( 12.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;