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: 13900701 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E441DE77181 for ; Tue, 10 Dec 2024 02:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8098C6B00E9; Mon, 9 Dec 2024 21:41:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 76B6F6B00EA; Mon, 9 Dec 2024 21:41:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E5E16B00EB; Mon, 9 Dec 2024 21:41:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 369A76B00E9 for ; Mon, 9 Dec 2024 21:41:29 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B356CADB35 for ; Tue, 10 Dec 2024 02:41:28 +0000 (UTC) X-FDA: 82877498088.29.365957F Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 65677140004 for ; Tue, 10 Dec 2024 02:41:12 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lD51QISz; spf=pass (imf09.hostedemail.com: domain of 3VapXZwsKCEowmxq4t4uzsts00sxq.o0yxuz69-yyw7mow.03s@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3VapXZwsKCEowmxq4t4uzsts00sxq.o0yxuz69-yyw7mow.03s@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733798477; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nXKIsvWsBBTYmcaRz8JoUa2+7Qpfg8xMl3r7PMmLvBk=; b=oOeBOi7s0eTSGNsq0suzbRMhCQ6WC7EO+dvQpLvMU11OSMwC0RgYA0XArqtAiYFlXbgMir Xnr8MG8AYc1Gmox+SN10DD422eJNWC481sxHV95aB7Z0nfJQJU+MBJsaPLBeeZWJ/CVDR4 JjB35Gur0I+2N1o9/xGHu3z5uz8j3JM= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lD51QISz; spf=pass (imf09.hostedemail.com: domain of 3VapXZwsKCEowmxq4t4uzsts00sxq.o0yxuz69-yyw7mow.03s@flex--kaleshsingh.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3VapXZwsKCEowmxq4t4uzsts00sxq.o0yxuz69-yyw7mow.03s@flex--kaleshsingh.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733798477; a=rsa-sha256; cv=none; b=QcQzW0IxcWD6Cw1QofADbgLqFWsONp79wT5Po3QF+cjUFhJwVSQvctKLVfXqZuFVmXcV6q xHjPwjQHwJi8XcurqXQXLcHOrBozRPr8JDcQOy7ruYeBYX+UfuqVCSDHki67Le8mXRqOFT Jq0CtGmGX5uj/2ZBB7OgEWQXh6gCAeQ= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7fb966ee0cdso3579482a12.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=1733798486; x=1734403286; darn=kvack.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=lD51QISzu+qm1vrXD8cqpcqDYA2OaAek7u5rh2/geBuxKL33YhM6IRfu8CLZ3NO1xU cUFhPFTwmK2Uq9KW7wY+F/7WdOEZc3d6Wu2oLcPtITnW62bnNjEYNxxpqoa5kiFEkLok 3pjxOw6KULWoZdEiLTu4W7k/WVFG5/RLTtH5lvteeQzcpoCOWloF3ocFg3fEBaZJgOLt rfDKTQ6PGxLhSrAbZJiXxwoGM1L1rzozmRFRnqXo+K7NIM0Nc1U/pZ5gP8rlymFxPSqT m444oOaDzsYmb6mOvbOia5QulKxYKERFVjTA0uH5DZLDueo8BZf/gjdEsaE34bBG7v3d HZuQ== 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=hsBA+Q0i4NU8+1BkAaAn4CxxE2G5LRpDl1qXiQZ/AdQv7aWf0XFKL55CL4vUAoe3PT 9TAMBzIc3RQuV189hVftLhls6M1BlwrSiLLLDfshW7TCHmToKEyAVfGB8QkcgKQY6Faf 4wR0s+mTkKN91FJQsPVrHDFysCCzlKUxeCiJa/t8Yd+ufhnFBMw4vI5tZdU7dONljbAJ i7FFfmNENJzZRsP47NR/X/slOl9WuRg+esPxE24qPnbGpvJ714YlegCxPmriGJiUGBRb 2LpveL44JHfUSjiNQN8ZcKo7stKGh8/fxsQh3cEHp0zI/9i0DBeT8YSTNa2WSJzL+WZZ e7Dg== X-Forwarded-Encrypted: i=1; AJvYcCUolS2QxeFCO+NK0KfgygoLT/uH3zseKWQSOVyhPQSmAHaVofNJOEQNpyhc7ZdQIBmLumjTpwq5hA==@kvack.org X-Gm-Message-State: AOJu0YzO8fM2XInpql4CMQWeaPBHow+SNqoSIh9DZNPUNAdOSetiuOQo 900ciA85GIcQ+HwHJyQ+Q2t2DPq5txL1JLV2Cz2syT05FDECtq1U2u3sPHHYO870oVoFQzjZjef 5OVxxTj3nXik7mP10u5ODGA== 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-Rspamd-Queue-Id: 65677140004 X-Stat-Signature: iiqeggdm7qeczd1hmmbh38m8azm58gt5 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1733798472-660330 X-HE-Meta: U2FsdGVkX18ckJe92NnNLGjJUFSFoqTGqU66/syo3aD32h8YiDmEzdNjVY+1/HljS7b1b0EAZZW8NEixWxzZYFXhgWZolW1fxkJPIKQcRX6iXyMUdXKTORFdRCAXaNzkfRGi6QVZlBvIVyxFVS9SMm6TlEHjY+21MR/Zq2Vvfh3+HXoZ+8r7aUNqPh2uebe+6gdJQYreIx8VtOn6PnNRQDojpNGesmABq0pPOkRrrbSAXpOI1qCyY4uea3XzpttIJw3+vlKk9hpGb0TN16zZIIXu8V2vZk5IFmHMs8hIwT9tU7BXx8R2c1cnP66Rtlwtzo103oFaML7U1EkN7dHOm1u3tAlSAO5KUw77gx3Yn+CkhgwK3wzO9kRtWkmJ7XmUIM6IsVSWTcV8GWRlG7/T1X7T7zJxAVv3aE7LuqJ/emynboTEDV6YQsJLAg+Y8gfman5B0nAF8vWVVNa0OLwprPfTmGSk9lMZm5+yPqzbf0LuQxKyX+vgvYitGMG+wjUWpPfPYGNKyQjVxuo4y8+yxflfbX29W3svTCovbVCafiYHttV4aXSAR4NLrOe/Qr/cMH25fzLMK8ufLQyajPSoEIauvInjFSbPg23ElqYwd4RAxYrq5viDsHaqrs4r05Hb1cOnec4OELj1c1yLOEmfmL17eIq4L+AZfzqoPDKHkwLEosKplxTCvNSyND1M41pBEuU2zbtoj6w3BmwV8IdyDzxSPV+shq0+I+xXMZNB/MFT3Jp/JZUeKQ/Fug25cgpbgp/n1fqt6W6CLoEiHfIBw/Myp7YIToLwrQwu3X9uXwH2JWJxZ8AAiI1g3a4+KjPJCGx4EtiT971OaDEGSBgr+y9CRgIfVjVZ0n9m7PcTO4CFzeKvNe451l6a1QKQj860DJaJR4qXUHEfTfbBY30U7sAGx8Quk7BwZPsYXGAaY6w2XCYjEnlL4EtjKU1Pe17bD8YO7plKBA8MiYj7Z4Q Aob+gmt+ QHhPkLaC6jQI8uk5ITRIyF8ohFFLQkcBIPRGpVzivgjuM/3s0wL6NHZbp9llrY4j5Xtd7jFH5Vc0litqWWR3Oj9bSETB8Wvu2KGDo48rAWGLALR8emSaqxPN3ouBik6sISwFiC/u6yZEsJb5xI+TMHFE7VZ2PYWuWEcSQk4jKUOG8SdULqlO5U93jUOOeWzrMQ2Fs1p9Vug0cYIu+KJa711Lc4AzRERz9XvehubUx/3f+/RH18ltHHeH5PYAaq2hOmMdEOG0NmBXbRDwWR7OA+gW3aV/Wj9865A+5FyuvtcHJ/Tpu+1fMwSxTjn6CUn/B+wV3Aqj5JMTYm0cq95+iWGlh3UHEEkWSDW3tfRRorlD8+uFxVSz/O4UV3AW54mAuUBIO5uilzCuePpfzbq9DjfukiwhbU0RSZsOxPHlmUs7RAP6zFx5Ggu1XN4em+EoUc4SsxB/Hne8PM1WRMX2uSx/uHHnTDoie44RSYBYD9xEMzDoXugbGFYRUez2dzheau11bbFLlaTIMD2sqdDurJ4jg1Tfwru97OenikNEo6o5A1TWWYfACaKObBBu2Z31TUH06JIzqLszhC3as227LEUt+X+l9MftzfvZUeCfPAMBy349rZvHsjBDgd7A6lmPbJ+ph+heaoQuLpCzreJJbdZX0ljTF0PXfcATa X-Bogosity: Ham, tests=bogofilter, spamicity=0.079646, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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;