Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp32353rdb; Wed, 17 Jan 2024 16:10:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwD9BgDnJB84/Cc7pW9LSCwN7IW5OBxD1xKvg6VZYMxNicPSUqi595vz7J/LVkRyHhcNIU X-Received: by 2002:a05:6358:590b:b0:175:c18e:81ec with SMTP id g11-20020a056358590b00b00175c18e81ecmr98955rwf.1.1705536607371; Wed, 17 Jan 2024 16:10:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705536607; cv=pass; d=google.com; s=arc-20160816; b=eBdC0Ppw6RDVhZ9xGM51pJInwQZObSEcxKrjO2m/11MzZ+hUaa9P1+G0rUsuAASgk3 k1uYh5QZMPlUznvBURFek+S6bIDohK+AqerXSETPzu14qTlqW+3LwZSdH2yLCmbNTEhM pbUS/GbjHrjTcr4Fu1oojZbI3zh0dmFMdqDvGvKxJAhDbb6F0wl7XuUwZS9gs/8F6Kbt ROCaISLXoNiTwiLL4bfeiI8IUKDgzwiMrcdy7Cafrq3qoatRmaBqA+PbJHPX8vmB0Gw3 TpohbHHifgBBK1mEWdbzg/SAgfGXqUA7GW6o7Y4kwZjoyP3RssA73L0evyPM78JuIfBi V7Qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nWj/m/g6g6US/nsTw5NmJ8dd+nkVoLNoyL8nmayW6s4=; fh=qLcLLEdaiU6qjAz+892ZQ7OTQSl4WasekeKP0c3BjA0=; b=ePxYJ8QrGFvgtMYpf1O9lKV0KUkws7tgyfEl28CzNN3g5StxHA3MDZiQa6Yg8H6Rug jxKP4aVhqGjxDhq0IAfCUBVmSQzca8UWBa8AwAHo0eNOmrMYkb7+Yu83PCCTrm0P/4Db 6z50SlcPfRYCkiZXTqp0pNp4YPy7AaMBSispf0FzWo0ZDQDp5EtMpyTvaVhGcbdYMcou 4HQ0BHLovcs0E+dHD1zM7IuGfkJzpbdh2v51IMql2xsMC67gt38oGXlaJu+bNBuq/PrK lEJiEFrtrD1HOQX3ujOdG72TgTf3UPam1dwRmKa8mZyO7MGgfyLchSIhzzsvuQekc+mX eITw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uuGLPp4Y; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c4-20020a633504000000b005be03f0da7csi457528pga.61.2024.01.17.16.10.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 16:10:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uuGLPp4Y; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-29576-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29576-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AB598281FF7 for ; Thu, 18 Jan 2024 00:10:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29E6E39B; Thu, 18 Jan 2024 00:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uuGLPp4Y" Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9439191 for ; Thu, 18 Jan 2024 00:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705536600; cv=none; b=VqCAwGVXSZDSUuWlg2bZreraQXvMTRziZb8E1xC9fx2RPkpn+iBWN9kPABtm2HWBDBTaW3Mu+4tbJ/F8tuU9MlzJXeoR9rKxBkA83kR3ok5CnMAyM9HUWGCNz0mYE7Sw8viKG6q8SxpdHR3bqO/rBfLmOzoNcHlbXR2i4GiCe7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705536600; c=relaxed/simple; bh=6NPTBdTuM2318YZyN9z5uQFEN4h2zarvDoRSHlB5Seo=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:MIME-Version: References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc: Content-Type:Content-Transfer-Encoding; b=ocmHh2NfzXHcN+ij5Vg/eeyBvBjdvN9SYdu6FelMr5L2xHUT7mHAC1luu+1hdF4GGwee9ay/URU6A0+m6m7q0LCrdykSdPE0H97R4qDE4LV0QOAA6xvD8XVTeu4lwaJ4xyQ9PXJvI1tq+iXt8A4I6Kqdd0k2lLFzN2ILMkXFQVQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uuGLPp4Y; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-5f75aee31d2so105635037b3.2 for ; Wed, 17 Jan 2024 16:09:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705536597; x=1706141397; darn=vger.kernel.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=nWj/m/g6g6US/nsTw5NmJ8dd+nkVoLNoyL8nmayW6s4=; b=uuGLPp4Yci7wPRl4aPxxeqsiAZd/sOAiaD31spLKv+Sh0rZzOfzG88bfK27vVePgyX Co3A40uMZjjquShHaidXbPRRyeR2dngkcpgZW2CJF6ExFgQT9LLndYC1yPoU7C4kOIOV pVVVBF02miQfB7hiwnvpFVLHKsGNHnMoavFsDDUKpuat8dV9g4VmI4QKqKQkAsi7omZb TwLi3AP9a4KPxWUaWC0LnE27tcbIJnJHTXek79BoQCcJ08iMmGinJON8DB83hTjBcPaA 50GirfdaZtKb7HtI1DOUkn7dS8ijOMkQS4P5P3NuBDSJRk30CBE1D7B2IQ1Vf2e7drpt flWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705536597; x=1706141397; 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=nWj/m/g6g6US/nsTw5NmJ8dd+nkVoLNoyL8nmayW6s4=; b=gMVIC0mp2O+OS72yyFFhK2cnn04slEUowMoa2salxSn5ar4B++EIPO/ErpQ5XYA9Ms Vqxr+HgBxAnt/xPu1iY+5Zy38VYfdo9N81XmsmA84VIUiN9Kd4jRLFJQeaufTZQJBRL2 Ylr8gPX9Povy+exJbffye2254mW9CHHbLYAIv7zquHDGqZ/0Y2BKG7x1dU1+RBQh3ba7 WdudLPuQXdx8Gls6V6IGJNVKeMYnJjai5ylE1Ud4/zybtUjg8ljXH6gV29izY1+FZ3sN 5f8mQxsbmXddTY+ZsrCpqPZOGWkiLQLraX55fY3RcBV5OMrVZybgq/KJTkHfwuXn0ufv l5+g== X-Gm-Message-State: AOJu0YyifW9yF3lWFut56UwwmeAQ0ORidnb6BlKoLY5LyZzO4vTcNJiW /dwHIErXIVFBgcTYbednl9Fx3Z5FBa5cpVNrBfR3TwpRFUkfmIiP+TAeyP2rPlY7NiEdS/sXqvi uJywz9K6MtXvIDup0vm5RhJSac+ANP5lCuAdl X-Received: by 2002:a81:7103:0:b0:5ee:82ad:5151 with SMTP id m3-20020a817103000000b005ee82ad5151mr32472ywc.74.1705536597460; Wed, 17 Jan 2024 16:09:57 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20220809142457.4751229f@imladris.surriel.com> <3193bf5b-4e22-412f-8c5b-68574942d9bc@kernel.org> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 17 Jan 2024 16:09:46 -0800 Message-ID: Subject: Re: [PATCH v2] mm: align larger anonymous mappings on THP boundaries To: Yang Shi Cc: Jiri Slaby , Rik van Riel , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Matthew Wilcox , Christoph Lameter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 17, 2024 at 4:07=E2=80=AFPM Yang Shi wrot= e: > > On Tue, Jan 16, 2024 at 4:09=E2=80=AFAM Jiri Slaby = wrote: > > > > On 16. 01. 24, 12:53, Jiri Slaby wrote: > > > Hi, > > > > > > On 09. 08. 22, 20:24, Rik van Riel wrote: > > >> Align larger anonymous memory mappings on THP boundaries by > > >> going through thp_get_unmapped_area if THPs are enabled for > > >> the current process. > > >> > > >> With this patch, larger anonymous mappings are now THP aligned. > > >> When a malloc library allocates a 2MB or larger arena, that > > >> arena can now be mapped with THPs right from the start, which > > >> can result in better TLB hit rates and execution time. > > > > > > This appears to break 32bit processes on x86_64 (at least). In > > > particular, 32bit kernel or firefox builds in our build system. > > > > > > Reverting this on top of 6.7 makes it work again. > > > > > > Downstream report: > > > https://bugzilla.suse.com/show_bug.cgi?id=3D1218841 > > > > > > So running: > > > pahole -J --btf_gen_floats -j --lang_exclude=3Drust > > > --skip_encoding_btf_inconsistent_proto --btf_gen_optimized .tmp_vmlin= ux.btf > > > > > > crashes or errors out with some random errors: > > > [182671] STRUCT idr's field 'idr_next' offset=3D128 bit_size=3D0 type= =3D181346 > > > Error emitting field > > > > > > strace shows mmap() fails with ENOMEM right before the errors: > > > 1223 mmap2(NULL, 5783552, PROT_READ|PROT_WRITE, > > > MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 > > > ... > > > 1223 <... mmap2 resumed>) =3D -1 ENOMEM (Cannot allocat= e > > > memory) > > > > > > Note the .tmp_vmlinux.btf above can be arbitrary, but likely large > > > enough. For reference, one is available at: > > > https://decibel.fi.muni.cz/~xslaby/n/btf > > > > > > Any ideas? > > > > This works around the problem, of course (but is a band-aid, not a fix)= : > > > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -1829,7 +1829,7 @@ get_unmapped_area(struct file *file, unsigned lon= g > > addr, unsigned long len, > > */ > > pgoff =3D 0; > > get_area =3D shmem_get_unmapped_area; > > - } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { > > + } else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > > !in_32bit_syscall()) { > > /* Ensures that larger anonymous mappings are THP > > aligned. */ > > get_area =3D thp_get_unmapped_area; > > } > > > > > > thp_get_unmapped_area() does not take care of the legacy stuff... > > Could you please help test the below patch? It is compiled, but I > don't have 32 bit userspace or machine to test it. Hmm. I think you misunderstood me. This is happening on x86_64 emulated sys= tem. > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 94ef5c02b459..a4d0839e5f31 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -811,6 +811,9 @@ static unsigned long > __thp_get_unmapped_area(struct file *filp, > loff_t off_align =3D round_up(off, size); > unsigned long len_pad, ret; > > + if (IS_ENABLED(CONFIG_32BIT) || in_compat_syscall()) > + return 0; > + > if (off_end <=3D off_align || (off_end - off_align) < size) > return 0; > > > > > > regards, > > -- > > js > > suse labs > > >