From patchwork Wed Jul 10 10:50:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13729170 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 E8426C41513 for ; Wed, 10 Jul 2024 10:51:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF6C56B009C; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA4B86B009D; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF5076B009E; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8AF476B009C for ; Wed, 10 Jul 2024 06:51:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3DEDAA29E2 for ; Wed, 10 Jul 2024 10:51:27 +0000 (UTC) X-FDA: 82323526614.07.0A35C73 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf03.hostedemail.com (Postfix) with ESMTP id 402E020006 for ; Wed, 10 Jul 2024 10:51:24 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720608659; a=rsa-sha256; cv=none; b=COdCTzCRI+TGeH66vaBiZB4xSrHsGw7Zy1BJ9MM8R3ZBsz3K/kM2IJ9Dzj0V44SfOZC8W1 Qh0edU9ZQJRgWh3u/2NXRzYnRwtnBdOjNZBCD8PO8YTKZw93O9NS61gVfc+C3wWtAGk6QY gVHyXUt7A2ADuApG5tZObuG+PM75zog= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf03.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720608659; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XSQhKhxsB8mJo06ul8PeKZx+ybzEA5hBxV4gU2MOqSA=; b=lZ1RGS2oaAXzNkPcPkon393BW9vNjGhnYzN338yTKLtkBFy+lzU5ANq7Y6poqGyTP4IbGw fKJlxuggBPh09kZrTmSTle/EmcriMQp/uatDZkADWrKTuEM6fx0En92w7zb47Ep60XZuuT M2B5gUSeD4korSCDwzHMt32k52nifrc= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D223A21A3D; Wed, 10 Jul 2024 10:51:23 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C8C571369A; Wed, 10 Jul 2024 10:51:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gMnALKpnjmazcwAAD6G6ig (envelope-from ); Wed, 10 Jul 2024 10:51:22 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song , David Hildenbrand , Michal Hocko , Donet Tom , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Oscar Salvador Subject: [RFC PATCH 1/8] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Wed, 10 Jul 2024 12:50:35 +0200 Message-ID: <20240710105042.30165-2-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240710105042.30165-1-osalvador@suse.de> References: <20240710105042.30165-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 402E020006 X-Stat-Signature: 4hjybegrxrfnw1deytuzzqisguyf37un X-Rspam-User: X-HE-Tag: 1720608684-156361 X-HE-Meta: U2FsdGVkX1+O/Po1iCi2ygkl+9qNWmHoqHjwbuIIEcfh12rZNcsI+b3GUq4xBnQNMWe9I9YdwepX4+W7OR5MI47d2vSKou9mrPGbL5w+Rm+yIF2HFIH/VHmfktR5bOiJ/XDzm7zd36Wclasm/4JxVZg8ibA+N1kBioFVxEJ4x8rBEoKQffcCLdAhuaxnYZ51a1NbTHf08JC7tDrpBUhhNOKsGTrU85eMD23rcB/Wx/fhFOkacCkbxRX0vhAmBSKWG4ixq6z9VUtteJkg304O9NVug+YlS2r6pQo+ezt+00XLg8aKpMwBJeNg4omwaUW+nV9hu7sQDtVeAIlm9XO25xFxdbm8gzNObz4itDN02EgloNiz3I/TMsROp+dEx/SucN4aJgJLfUPj6ZwAKTXzlent1xiNOHwBtD/Fpbn7WxBUnwxP3o7lMjYJBNjWfPO0U9kmwXBbwsH0b0V4TjABBpIOvgGO4nLpF0U/Ck77VLjx1YWZY3/b65nxQRDhrqsDs33YPeLM00e4mPd/0HpmAXs5OQwIVrhWzHUNKwDVqpkAJ50IdcmkBIbkNw03jRtJOA6AJbf5qP4Ql2tYUlfiqNWusdlNEQVm/H1DwCFYULalLWspxZOS/gwwUI7jajX0gptTcapJmzYlODN0EBqW0MiiQ7SOqoWMX9E42DZJDfMFayUxHaJRmLRI4hDhXoneDmGA4ERb3VdXk3hCzmA2YIbidwYI+xnKXPA0t591Mv1XZzVL0CpEHqwhK+C8FAI6OXbxAKRqEYjDV5Qdq54EzaqRP5h4lvaZDgFvUXKMJmhwQSQJ8LPeqit0eL+O8iilUVzGGnnJ372CIu1BhjFqkcvE7b9hWBaWWpTnv+ikylnnI2mIua1uyL987DbrMYdKTh5tXgyYRsRecV6V3ENO6wEk6GQtSlXQfrG1ZT/5HGh04GvQs/lapJDFW2LgpNKDKip0EWYnodUimimjbhE bM9gyjrt IlsYbVLDokBLTFONFIwtg/ZisyVrpUrRxQn85SRchlu6x+uRQgu53Loh9muPbgXZsR8vfZGFJkIX4JUhQFZdgZbHlNqsA6BXyuTnOWlEfL+zbh/AVKfmhGqPXwfMwl1OyTZH0WzJZSiZtQZBHguMgx4U476nSX/1weVBL7jZ4wh8EHQQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to stop special casing hugetlb mappings and make them go through generic channels, so teach generic_get_unmapped_area{_topdown} to handle those. The main difference is that we set info.align_mask for huge mappings. Signed-off-by: Oscar Salvador --- include/linux/hugetlb.h | 10 ++++++++++ mm/mmap.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 2b3c3a404769..1c7b0b32ff7e 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1029,9 +1029,19 @@ void hugetlb_unregister_node(struct node *node); */ bool is_raw_hwpoison_page_in_hugepage(struct page *page); +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return PAGE_MASK & ~huge_page_mask(hstate_file(file)); +} + #else /* CONFIG_HUGETLB_PAGE */ struct hstate {}; +static inline unsigned long huge_page_mask_align(struct file *file) +{ + return 0; +} + static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio) { return NULL; diff --git a/mm/mmap.c b/mm/mmap.c index 83b4682ec85c..09131b705e7b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1743,6 +1743,8 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, info.length = len; info.low_limit = mm->mmap_base; info.high_limit = mmap_end; + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); return vm_unmapped_area(&info); } @@ -1791,6 +1793,8 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, info.length = len; info.low_limit = PAGE_SIZE; info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); addr = vm_unmapped_area(&info); /*