Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp944290rdb; Tue, 23 Jan 2024 23:03:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IELBbyKnnbH6zOzIYlCI6bSf3Pc/f3lOtfGDnae2jbSxUvL3rTqK/i36bkyZM29Gq82DY9D X-Received: by 2002:a17:906:4894:b0:a2a:399a:9bcf with SMTP id v20-20020a170906489400b00a2a399a9bcfmr360058ejq.222.1706079818533; Tue, 23 Jan 2024 23:03:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706079818; cv=pass; d=google.com; s=arc-20160816; b=b1hKTisDHK8hD6CRfWK2WusUTSLlb6+OQLAQeQJXD6aUNBE9TcIdRu/j/g2Xz2Sv3x 9I+pSd2MTPJnRR6yFN2p6/5GcOpVUBO1Cdnf/dJq9jdWKpnyV7T6fY2t0Kt65l0AzIOc dJlNvp4j0mOq4wDalFAkDKrEjwxyDWhqS26AUFvI5h1NiY1KCaCFBm19C8EOHozdUF/D HRZdE7c9E+0luAl6KHJ0qVSdREz1BEybUHh/T4Q0D8RuqhBbtr3lORUMahPpaE3hStob R29ZBthlnksH88s6CI3+SpFaOWVRcecvBU07YwTgabaLDM5FnoQoqih8o4kMzCRi2fqC YW2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:dkim-signature:message-id; bh=1HVP16o1VtXDA7W9OZNwq3dT+EsNFJe/EB2vPP8VZRM=; fh=JGHXd86NaCZixqTqmCHrDBhHJwbiEGQxXcfybmZpS7M=; b=F+ugYbuCIvdTS6qmdmd/PN0B9WbBL6IaAHuBSUuEPY1xM7iy2xZLbql1CzNYeXSUe7 AfSGqkhAZiCtre9yF49gzYF4lIvHm5ErwNOvIdzwMNAinz3QS7n80B5MnwaMFWx62Zz8 j6Ougd7XsBoMjz9ZCmhsXz7i9+Wk3dXmNdAOSQckvy6bgfdSElz2keGXA3bE2NiiuCKd K8Bz0Y6mEpMR91L57uW84FdsY/DXNg2s52IkJQd5BYoCquVldzbyKcRduu//eLfxoLLA I12dPaDbkmY6KJ9muGAhFWn78l/pfh99Cb6DQqHGX0dO9myH0kHuY9qWVoXkcd5y8ZhJ Yelg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ccXBI1cM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-36530-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36530-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m14-20020a1709061ece00b00a2e92042f51si7980540ejj.247.2024.01.23.23.03.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 23:03:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36530-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ccXBI1cM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-36530-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36530-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4DA931F28EC7 for ; Wed, 24 Jan 2024 07:03:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02D9716415; Wed, 24 Jan 2024 07:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ccXBI1cM" Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB95910795 for ; Wed, 24 Jan 2024 07:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706079809; cv=none; b=D92pFuQMHOXWspdt3gq6Cd6Hjm73VXbFQRml6G23ocjazTNrisnmiGUxA06KPjWhnZsZoL1w7FFcwK/lCpkVrtT295BMU+dtFA6BNyeG79FsKKTGSw2NrTAuDZHGuunb3ZZ5TEeGx6wRaSTg1iQH/HZFgiZpNZc2kgvuk8Yscvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706079809; c=relaxed/simple; bh=P19nx0w9knko/JVFAMwr4eRsuGvuoHIsDKUWA+RaEUE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=vEASjHYsc80h3HSl5HW0qVed+vq4dun2rUPkGsg5argwVZuSaLFd+tTpxKgG5BVCFdIAdRivvA1lyuasodPqmbh1AYkLMv3cRO7L7MSYUjWrLycbboVbx1H15lczz0fXtunCH8yrXundnF6TGCVz0AJ3mKY8d4GX+oPDNjU8hiU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ccXBI1cM; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706079804; h=from:from: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; bh=1HVP16o1VtXDA7W9OZNwq3dT+EsNFJe/EB2vPP8VZRM=; b=ccXBI1cM3RgoCTV66lUC3XI2f9ilnUOAyO5eHsoD2RskZr6BZipluQmDZutMDOzM9Tl9YL 3E8DjOCDvljN0mPiMgBErH1linpiUX9Ch3B3Ggij+N+IrJ0eFTGsXM4juNPCV8FKfEiyta I+l098X1/g44btaBFjEnItvBkxNl6BY= Date: Wed, 24 Jan 2024 15:03:15 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3] Hugetlb pages should not be reserved by shmat() if SHM_NORESERVE To: Prakash Sangappa , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: mike.kravetz@oracle.com, akpm@linux-foundation.org References: <1706040282-12388-1-git-send-email-prakash.sangappa@oracle.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <1706040282-12388-1-git-send-email-prakash.sangappa@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/1/24 04:04, Prakash Sangappa wrote: > For shared memory of type SHM_HUGETLB, hugetlb pages are reserved in > shmget() call. If SHM_NORESERVE flags is specified then the hugetlb > pages are not reserved. However when the shared memory is attached > with the shmat() call the hugetlb pages are getting reserved incorrectly > for SHM_HUGETLB shared memory created with SHM_NORESERVE which is a bug. > > ------------------------------- > Following test shows the issue. > > $cat shmhtb.c > > int main() > { > int shmflags = 0660 | IPC_CREAT | SHM_HUGETLB | SHM_NORESERVE; > int shmid; > > shmid = shmget(SKEY, SHMSZ, shmflags); > if (shmid < 0) > { > printf("shmat: shmget() failed, %d\n", errno); > return 1; > } > printf("After shmget()\n"); > system("cat /proc/meminfo | grep -i hugepages_"); > > shmat(shmid, NULL, 0); > printf("\nAfter shmat()\n"); > system("cat /proc/meminfo | grep -i hugepages_"); > > shmctl(shmid, IPC_RMID, NULL); > return 0; > } > > #sysctl -w vm.nr_hugepages=20 > #./shmhtb > > After shmget() > HugePages_Total: 20 > HugePages_Free: 20 > HugePages_Rsvd: 0 > HugePages_Surp: 0 > > After shmat() > HugePages_Total: 20 > HugePages_Free: 20 > HugePages_Rsvd: 5 <-- > HugePages_Surp: 0 > -------------------------------- > > Fix is to ensure that hugetlb pages are not reserved for SHM_HUGETLB shared > memory in the shmat() call. > Signed-off-by: Prakash Sangappa BTW, it is better to add a Fixes tag to specify which commit that this commit aims to fix. Acked-by: Muchun Song Thanks.