From patchwork Tue Sep 10 08:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13798082 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 7132DECE564 for ; Tue, 10 Sep 2024 08:01:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F142C8D002C; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7AEA8D0029; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE22A8D002C; Tue, 10 Sep 2024 04:00:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 745F88D000E for ; Tue, 10 Sep 2024 04:00:55 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 24BBA80F61 for ; Tue, 10 Sep 2024 08:00:55 +0000 (UTC) X-FDA: 82548082470.05.3871A90 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id BA5411C000D for ; Tue, 10 Sep 2024 08:00:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725955248; a=rsa-sha256; cv=none; b=Wg/StVYnvlvOSgd6f8Vm9vE+VLpJFJPr9gCW1+SY4eUrw8C8PbZ4lRqSBnWuzKiCIEtr8H 41y5QM1N8DgojrehiHmc3T7ooxjoetubtOF60OkJxzm4I9jpcmtVH76aoFjw2gPeucik5o 2sxtDEycCszyp7bfIRUbFNUtb7QCUak= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="P3HH/9Ve"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=6+VaV++W; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 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=1725955248; 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:dkim-signature; bh=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=x6GWFX5p4ya61UEubBbJUKd6MPWXU+HO5k6CyvPHuwNdH6BIUZPL5172PAqNeKm8l5dM02 s8t6Wo07tHHkEuCtf+ZO50uy/tOiuR+QSRpNxqzMJLZeZvdlDdtmPyYTRO5B1kL3jAxhtJ a2ZoGhVW31bmuTnZAK2ANeF007ZRTkE= 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-out2.suse.de (Postfix) with ESMTPS id 72B111F80A; Tue, 10 Sep 2024 08:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=P3HH/9VeO7/hs9W02KLJGbUQbz6TwJPMh5eQ2KsOessc88XZDb+B6rbkgJV7KGjJn2IK5n WwCZ4BHpYGeWoIN4Ie98Txw3mHCx4CHPS5VeOI1MGATKiQFg45BqH1XQVwFWME2xGaWt78 tzuUkn6bEwf6leksfA/2wbq3i2lZctU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=6+VaV++WekZwnCQTHieIrPzmnni7tH8IuusN+gNlU2UPhwMNZ6FIBnLeq4wzMa7ZyDqDBr Dalx+1Wzn0NIrvBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725955249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=P3HH/9VeO7/hs9W02KLJGbUQbz6TwJPMh5eQ2KsOessc88XZDb+B6rbkgJV7KGjJn2IK5n WwCZ4BHpYGeWoIN4Ie98Txw3mHCx4CHPS5VeOI1MGATKiQFg45BqH1XQVwFWME2xGaWt78 tzuUkn6bEwf6leksfA/2wbq3i2lZctU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725955249; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dh8ID66bUaRGXz2gnq8rzcTDLeuCZFk4H+eROj1OqJY=; b=6+VaV++WekZwnCQTHieIrPzmnni7tH8IuusN+gNlU2UPhwMNZ6FIBnLeq4wzMa7ZyDqDBr Dalx+1Wzn0NIrvBw== 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 AC6E113A8F; Tue, 10 Sep 2024 08:00:48 +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 KOYuJ7D832Y2MQAAD6G6ig (envelope-from ); Tue, 10 Sep 2024 08:00:48 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , Donet Tom , Vlastimil Babka , Michal Hocko , Lorenzo Stoakes , "Liam R . Howlett" , Oscar Salvador Subject: [PATCH v3 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Tue, 10 Sep 2024 10:00:22 +0200 Message-ID: <20240910080030.1272373-2-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910080030.1272373-1-osalvador@suse.de> References: <20240910080030.1272373-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspam-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F6m4KrC4WNWsjr6 o1mNI0Du 5FQGvskhl27IQ7gPknd2c1w6mjQieFc3P9IH8sUi9glMrVF0H5OpUHpxhve+y/SjtO/Bq7hIA+Yx6gYAau0VDa/cgoJFCSk5p4ExXUwwxKWQvoNpJpR+zczvHm7TIR5j0uoeVut036AiiUmd28BEHbK2puhDInuyoWFZnVOmQWwcphnhJUR87sowcOBeYDVt0S56dZKRpeWCId1sdg1hADGjOS7SU7knRrkx6u+Yj9O22TvoOG8j54w4OoH1Z3pAiZvT1HQQTl9I11ZutuPzHoEEk9w== 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 e4697539b665..368d552e4860 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -1035,9 +1035,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 270bd8d504b8..5f05df7d58f5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -776,6 +776,8 @@ generic_get_unmapped_area(struct file *filp, unsigned long addr, info.low_limit = mm->mmap_base; info.high_limit = mmap_end; info.start_gap = stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); return vm_unmapped_area(&info); } @@ -826,6 +828,8 @@ generic_get_unmapped_area_topdown(struct file *filp, unsigned long addr, info.low_limit = PAGE_SIZE; info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); info.start_gap = stack_guard_placement(vm_flags); + if (filp && is_file_hugepages(filp)) + info.align_mask = huge_page_mask_align(filp); addr = vm_unmapped_area(&info); /*