From mboxrd@z Thu Jan 1 00:00:00 1970 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 289AAC35274 for ; Thu, 21 Dec 2023 19:31:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 452746B007D; Thu, 21 Dec 2023 14:31:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4015E6B007E; Thu, 21 Dec 2023 14:31:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C9586B0082; Thu, 21 Dec 2023 14:31:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1AD956B007D for ; Thu, 21 Dec 2023 14:31:52 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CAB2FC0E29 for ; Thu, 21 Dec 2023 19:31:51 +0000 (UTC) X-FDA: 81591820422.05.56D043F Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf26.hostedemail.com (Postfix) with ESMTP id EA88B140029 for ; Thu, 21 Dec 2023 19:31:48 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bvHHw8rO; spf=pass (imf26.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703187109; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fJYWaKMWlPWX97f2qeaiw6ZVBBad2oJe+BJ9C0VEsB0=; b=c7ovlkLMOVqHgCmQELf9ZAIZavqtHAO+4MjwJsPdwAcn6fWbHw5AsbMece3w3bUxQFOpK+ w7gwzfa84sADPJpLRQkCSn4Zo+Epz5y5n990P0h1Ecp9tANr+cSL0uHWI69LU2wSQshFBg k2pYT8r8/uT46mqSx9VaNbxukfoCO+4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bvHHw8rO; spf=pass (imf26.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703187109; a=rsa-sha256; cv=none; b=xVZRw3VO8/SUIQe+B7FjMw9NObzt337uslO1oqYXJT7k1kNuMJf8Yje5JwLY8MvGz5eqNd PeFrm0cQpGIDF3sjUkLaS/fT33Ndsz1V1nKWbz/LAiephDM0yIQsGtfNBIQP6YKRr+g+6K H5l3px7naHwikV4zUN7uUUa155z4UOQ= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6d84b68a866so776777b3a.0 for ; Thu, 21 Dec 2023 11:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703187108; x=1703791908; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fJYWaKMWlPWX97f2qeaiw6ZVBBad2oJe+BJ9C0VEsB0=; b=bvHHw8rOxa6qDFfCR6vYEVxTo8vLyRVsjl3+lcY8hFnMeHGeBqp4lyTH/ppgmo1mPr Y3RREfEPHpEVW0aNSte74fVIkz4gCPqUghsLSFHLSrhsrHX+iX9P+eFxf/L65SXs4pLq H06AQZJ5wgGLRh2L9Rm/zJXVq+F1ZiOKhG/hIW5yRHv0kW5jQSTSzpBRl6oCEmvEqE22 p+uOG5I7t9zGjc3a5Qw3KimCfoXtZJXyBp6cMi2rYHcTyb8zO2M6IWCSxLDF0HKvF76B Qb6kkU/c79evhxsDmD+bue/nGL4llUER65gO7gJoYf5B14i67Krze4lqWN2i7kCkcYhU Optg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703187108; x=1703791908; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fJYWaKMWlPWX97f2qeaiw6ZVBBad2oJe+BJ9C0VEsB0=; b=BX6IAmsndkJutq8yL1dDbKhmF6+ucJMjB+TmOXLJamb2SkdBJKj6OhMlrR7/NoEMso mejcInFaL6n2MBUL0QWCxkS+BlIswgl7roTAP0NhOd2JLa29RRDq2T76c1Ju2e0rgaeR b7riqWjkTbYyoMUcAHJNkQCjjGxVR+wqb0gqeHxtwcU2xb1iKY6xtEh7i743b33RR5Ks yYOWy8Uxk1grDob50+i1HOwqCOsQoqwZMNN6mr58r+Kxxlnw6fXxAbDEry2Aq3STivN+ q6Kbh4Hhx+4Jo8rs7QeF8uw0yZ5MHaHlGgZTS0fy6px0a8u/I2zzzt0g2hrQXzDLk3ub jElg== X-Gm-Message-State: AOJu0YzV3aaTy/zLDL7/KD80VKIZQN7yScQnUv1pMY8R2ej8FsSC+8fw yYR4itbSPmAFAG523JYvGbUSyasYYHOW3juiddU= X-Google-Smtp-Source: AGHT+IF1nSEyK+v7jFyDMyGt7xnp/BX7BfxF1dJtoL9nqSxt83vxJI4pZry6n5b36QuxaxBn1qEBSZokGGtz5KKOltw= X-Received: by 2002:a05:6a20:4ca2:b0:194:dafc:d7ca with SMTP id fq34-20020a056a204ca200b00194dafcd7camr161710pzb.41.1703187107667; Thu, 21 Dec 2023 11:31:47 -0800 (PST) MIME-Version: 1.0 References: <20231220054123.1266001-1-maskray@google.com> In-Reply-To: From: Yang Shi Date: Thu, 21 Dec 2023 11:31:35 -0800 Message-ID: Subject: Re: [PATCH] mm: remove VM_EXEC requirement for THP eligibility To: Fangrui Song Cc: Andrew Morton , linux-mm@kvack.org, Song Liu , Miaohe Lin , linux-kernel@vger.kernel.org, Zhouyi Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: EA88B140029 X-Rspam-User: X-Stat-Signature: c3w7jcnommsc34qfnr753aobqz4fhip9 X-Rspamd-Server: rspam01 X-HE-Tag: 1703187108-330591 X-HE-Meta: U2FsdGVkX1/qkz9e2vujcmekSq6Ohl7dCO4nX6f6pcpqSauFOslb7toyjGFcfnWDuJPclsHNIuhBsWsfaitsLUbvB66srCPNU/YcBNzfMXbV0iSZG4u0WEFTi26TSm+NhilvowmnBVnOJCjVXWlquE9A6TGzWr4pkoq3UokwiM/rUkiAzYMeywDOrGy+ao8TxD2skA3al3ebB303N+umJZsptTbtvqNgX3hoMa+Ncc7BT3cLDIMDCC1/QcstsfKVT3D47EKxQaOV6UBX4OO7JtMVKOlCRhEz+yS+kWRj/cS5Gf8WHN2Wb+E/wVmBiv6Ibafm5mdfPOWGb1lO8xxsh0YQIdeTjk6UzZF68RD0MW8h9bDGa+dsjnQiYnSyRhNPRUPv5A5OIC5KTXRCknK9sbO6sGnEpmhoYmu9ukRFjFM0+xZPvMCTGMy48nFePj3STj2iiev0FdjjGRO0/zUKybp2RgHsEK8Ifw/0LrsRN5VTaN7MgA6+wL2Kiodt7f6LMxvQTTrPzij2I6O6JHkIgHlD5cw0sXO79pYjEkif9fb5Vnlj9q89D6SSAJPwoZn0cIgMXOmnzBQgOceuXgnUScHLyf/vS5bshmDucc5CQoTJiHRlqgPyyyMXNphV0qxKAUUdDu0guFhzTK4rQ06DZAnKq4OSwJ6wvL0oLwLvTWLcJB2a1Njc3xDsR8OH/2NWFJ+M1FvtY2Z+4U2+1t5BshQ7pT3o+1ARZfUoftQlQBiZr8nEV2Y3SEa7FNLDNNnuuvXGLJaElMqjxXm/9nm91s5u1WRg7x6LB5I/OETGOu7UBwiAXim9LCDJVw/055257e52vD94GoQsLAJuSMJNPyN8a8hiDi06rjZ6bnWFXPaJ8lrTHUlQ0CuO0DNeCsIy59My+svM4S7LG8C7gmNiReDVgrxBkc71Mzy97Td1U7APscLMuerd4+VxhT0kDkF9arMFxEF65R+6cjzhBp2 tda7zut+ iEbVJniqdEpy8Pq7Xy4TpkhkOEI7O79KI5GPvY3i3Y9hO+7HYMcdqwLh/3CmMuQX27DcxdvcYBudWOpcH1K5qd5CSLvjZ/D8wfIxOVDOk/BO63sSqGPrLRXdvpGyfQpMnycenEr5sN8e9WJ8Sgc1jm5cssZu1483igTSFky7NfwPq+oWAW/DYLkJ7Izk5nxCXdlWdkZR0abGGhHAIMQatc1snpk9H3HD9xCmJshLSAszKC+PmdizXLrBP3xCqcsplGKnBduBYU2zFBAJzizpOzZpwuyUvfFfe0ZOOociCQiScrdEANn3m6sVogHBezsMPHLQyV+eq7/Rpc6ttFxwKsXQtn5E4wR5QQYm5noCaqWfG58xu6Gcq54u8LASXku9DaDQwWmd9WcC3CiZAtDkbQGAiHIoUxy7V+l5BATixya9ldMbWKLMUeJgYyP5bp+S/tE6+yaIGuEV4aImq8OAHKuK/oEz5/fesnhtpuDr+Dda4MGrIETfHzUr7AHMJVLeQ1OMjsIuT459SMBpI2hrfg3AyAWcZs/w61E3TEVLIBFE5FesYuqIuDzP+I32c8h7T4SKtj/wf6gMIf+JE+tQRGhxKl3PzHYcF92sAtLAlK8J0lWxI2j+66j0p1td93pQ5Ll+XYFKZGXZXZ6WXplCYRQlf8WX1BvdxKjhn 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: On Wed, Dec 20, 2023 at 8:53=E2=80=AFPM Fangrui Song w= rote: > > On Wed, Dec 20, 2023 at 3:42=E2=80=AFPM Yang Shi wr= ote: > > > > On Tue, Dec 19, 2023 at 9:41=E2=80=AFPM Fangrui Song wrote: > > > > > > Commit e6be37b2e7bd ("mm/huge_memory.c: add missing read-only THP > > > checking in transparent_hugepage_enabled()") introduced the VM_EXEC > > > requirement, which is not strictly needed. > > > > > > lld's default --rosegment option and GNU ld's -z separate-code option > > > (default on Linux/x86 since binutils 2.31) create a read-only PT_LOAD > > > segment without the PF_X flag, which should be eligible for THP. > > > > > > Certain architectures support medium and large code models, where > > > .lrodata may be placed in a separate read-only PT_LOAD segment, which > > > should be eligible for THP as well. > > > > Yeah, it doesn't have to be VM_EXEC. The original implementation was > > restricted to VM_EXEC to minimize the blast radius and the targe use > > case is for large text segments. Out of curiosity, did you see any > > noticeable improvement with this change? > > Hi Yang, > > Thanks for the comment. Frankly, I am not familiar with huge pages... > I noticed this VM_EXEC condition when I was writing this > hugepage-related section in > https://maskray.me/blog/2023-12-17-exploring-the-section-layout-in-linker= -output#transparent-huge-pages-for-mapped-files > (Thanks to Alexander Monakov's comment about > CONFIG_READ_ONLY_THP_FOR_FS in > https://mazzo.li/posts/check-huge-page.html). Thanks for sharing the article, learnt something about linker and loader. > > As dTLB for read-only data is also an important optimization of > file-backed THP, it seems straightforward that we should drop the > VM_EXEC condition :) Yeah, as long as the use case is valid, it is definitely fine to lift the restriction. > > On my Arch linux machine, the r--p page gets split if I invoke > madvise(__ehdr_start, HPAGE_SIZE, MADV_HUGEPAGE) I haven't figured out > why it behaves so in the presence of the VM_EXEC check. What do you mean about "split"? THP got split into small pages? It depends on the address of __ehdr_start. If it is in the middle of a VMA, the VMA is going to be split due to the different huge page attributes. > > % g++ test.cc -o ~/tmp/test -O2 -fuse-ld=3Dlld > -Wl,-z,max-page-size=3D2097152 && sudo ~/tmp/test > __ehdr_start: 0x55f3b1c00000 > 55f3b1c00000-55f3b1e00000 r--p 00000000 103:03 555277119 > /home/ray/tmp/test > 55f3b1e00000-55f3b1e01000 r--p 00200000 103:03 555277119 > /home/ray/tmp/test > 55f3b2000000-55f3b2002000 r-xp 00200000 103:03 555277119 > /home/ray/tmp/test > 55f3b2201000-55f3b2202000 r--p 00201000 103:03 555277119 > /home/ray/tmp/test > 55f3b2401000-55f3b2402000 rw-p 00201000 103:03 555277119 > /home/ray/tmp/test > 55f3b3a9a000-55f3b3abb000 rw-p 00000000 00:00 0 = [heap] > > > It'd be greatly appreciated if someone familiar with > CONFIG_READ_ONLY_THP_FOR_FS could provide some notes on how to use > this feature:) I think your blog covered all the points. If you don't mind, you could add some notes in Documentation/admin-guide/mm/transhuge.rst. > > > > > > > Signed-off-by: Fangrui Song > > > --- > > > include/linux/huge_mm.h | 1 - > > > 1 file changed, 1 deletion(-) > > > > > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h > > > index fa0350b0812a..4c9e67e9000f 100644 > > > --- a/include/linux/huge_mm.h > > > +++ b/include/linux/huge_mm.h > > > @@ -126,7 +126,6 @@ static inline bool file_thp_enabled(struct vm_are= a_struct *vma) > > > inode =3D vma->vm_file->f_inode; > > > > > > return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) && > > > - (vma->vm_flags & VM_EXEC) && > > > !inode_is_open_for_write(inode) && S_ISREG(inode->i_mo= de); > > > } > > > > > > -- > > > 2.43.0.472.g3155946c3a-goog > > > > > > > -- > =E5=AE=8B=E6=96=B9=E7=9D=BF