From patchwork Mon Oct 7 07:50:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13824288 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 B5E6CCFB43F for ; Mon, 7 Oct 2024 07:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EB206B00F7; Mon, 7 Oct 2024 03:50:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2536B00FC; Mon, 7 Oct 2024 03:50:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAD566B00FB; Mon, 7 Oct 2024 03:50:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A687F6B00F7 for ; Mon, 7 Oct 2024 03:50:56 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 62E2D1C6E51 for ; Mon, 7 Oct 2024 07:50:56 +0000 (UTC) X-FDA: 82646034912.20.0B09D4E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf05.hostedemail.com (Postfix) with ESMTP id 43AED100005 for ; Mon, 7 Oct 2024 07:50:53 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="ADp55/pX"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1lcsC+83; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="ADp55/pX"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1lcsC+83; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728287276; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=tS8ojYk/QH45dC0tKET7RrvZrSAZHMlt0t903/jZ4kS6BIFjr37OePtdtH3FXsE5xFcxOF CRQPGajK2LTDIbEQ5iPAuO0ZncOoW6r6/ozNKtLXQu/S/srNzGIsKO8bw6ayjvYv9oa6kM 34mdwH0moNKEFx+A3bQfYTtsUWJwbxg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="ADp55/pX"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1lcsC+83; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="ADp55/pX"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1lcsC+83; spf=pass (imf05.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728287276; a=rsa-sha256; cv=none; b=CAEI3/XbkUAzAEL0lERL5Ye79LAbWPl2Ufi2zTOgrtV22NhqQdgNgR4lOHHJaxzWAUSrQv EYt81wlVoCHl+GJD4WlRlve25JGu8+AA8stf1YUYBx80u/FNBnoW1cgBZniAc6Q31iVOD3 hVl4RvLC9jxm4IBpJJTHVXecy7EUz6Q= Received: from imap1.dmz-prg2.suse.org (unknown [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 E86AA1F84F; Mon, 7 Oct 2024 07:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=ADp55/pX5WI3Mg9p7PK4RW8GW+Rn9bxI4wgI+2QNBq6Fe+4lbWESvGl+Utllq62MrtNWPk LB4wW1OQQDyXt1J0DpQ0hE9L5/KW2dCukUm8O4glSBuKyPypicn+56LITTQjvd1veOmfLa fsOiF7q3ZmEisIn4G3Vi8TEQyc/DUk0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=1lcsC+839ZcPy/lvLPaLQ2i4gypqWEjq3jXCggK/8NOMN8nPKQ6m/eM6boA6rBSXNvnygJ GhKSYRbkGEIf8UBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=ADp55/pX5WI3Mg9p7PK4RW8GW+Rn9bxI4wgI+2QNBq6Fe+4lbWESvGl+Utllq62MrtNWPk LB4wW1OQQDyXt1J0DpQ0hE9L5/KW2dCukUm8O4glSBuKyPypicn+56LITTQjvd1veOmfLa fsOiF7q3ZmEisIn4G3Vi8TEQyc/DUk0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728287451; 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=nToqOO7GlBoRNGFY8sGJEqoQNYfVFvYYnrXC4X6coa4=; b=1lcsC+839ZcPy/lvLPaLQ2i4gypqWEjq3jXCggK/8NOMN8nPKQ6m/eM6boA6rBSXNvnygJ GhKSYRbkGEIf8UBw== 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 48676132BD; Mon, 7 Oct 2024 07:50:51 +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 MH/ODtuSA2d6cQAAD6G6ig (envelope-from ); Mon, 07 Oct 2024 07:50:51 +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 , Oscar Salvador Subject: [PATCH v4 1/9] mm/mmap: Teach generic_get_unmapped_area{_topdown} to handle hugetlb mappings Date: Mon, 7 Oct 2024 09:50:29 +0200 Message-ID: <20241007075037.267650-2-osalvador@suse.de> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241007075037.267650-1-osalvador@suse.de> References: <20241007075037.267650-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 43AED100005 X-Stat-Signature: p3xemxpxqh6bqscy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+Iz9uiOMXRDmlWCwO9sejNY8ibkTskbTdWFU0g/EfIcZJr2WVMz0oDAu77cc3He4huD3UeqF5BUdBiUHjpSmSXDGyFa29DkmGquSzbcHW+O5T+mejEXm5Ri//KCKvkxRTtD9O8fA7OcHrfSo/UtbEjlZ3CL+ZJJ76s4JwNiVL7NDnu5cyE6HWkWJHQnOFZI6o3et5o8vjSW+efOpjsJzEwKZp3oJwuJjSBErS7woOMugfMX1P0Bb/+Ma5t+gB1T9f+HuCw== 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 9c0fb43064b5..57fd5ab2abe7 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); /*