Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2459531rdb; Mon, 20 Nov 2023 11:18:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJvbkDDwHYEBsQmPUqpfGhdOUC/rdwhj5aDwHYRbfUUQdCa3/WESDkQkMgh1dsT0gn0BVS X-Received: by 2002:a17:90b:3909:b0:280:c4be:3c8e with SMTP id ob9-20020a17090b390900b00280c4be3c8emr7779175pjb.48.1700507931901; Mon, 20 Nov 2023 11:18:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700507931; cv=none; d=google.com; s=arc-20160816; b=CeL7DVREuuKah8UurCOoOZHYXNTv3KvgPw23+rhqkJPvkbgI0XmCBZI22fWOtwTLXk WT6uPMIea3Ge0eFYKm8TywSkTHyGzKsxN/log/cdBxwE7q6rdddt47fULe2VUvVLi67p TAP/X01xAhR746eCmroy62JynUO3nHnf30vHNkFKj5ILhVUl3Ji/fEcBC6uSGcR0Mp4u d+hRQSUgzUvnLzFrP6rGDbCjsfpQ3FmL+CnDgfb804t9R5LA7a/oEKNhl6KaaMzX0xZn fBEr77jQVAXQUm/JKKMXL+/aBIFO27AkghOQInNHWXdxq8LaZxZW31+QMjKbLiAmF5hE M5NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=m2uesSr1RZAG/avk1Qh8AUkPhBEOaB3euOWyklILHFo=; fh=v/j7QEwtsj+94eMIzch1qbwAijHXRMR6IcasrHCGlTE=; b=w2GprQTZEefRr5Og7Fx1BnBLl91rD8lNBoz0JbN0clXwqeqzkpmEbp40giGIxS4QCL yN6FCZVzSM1SfQqRNHa7XyILEvFppOujICV4PWDiI0N59+dgz4PuMSvasul8WfBVhNyq lDvzc/NC2LhDARwfAKmHAAuxTyXfL9TZcfZURO2BK+YqC4/6lJOARFb2889CCabQtp4g 0UqGnF5dQZpmy8x2bIPHsg5H1kL/3FBrDSTUBfab3FuJVJvcm8ijvcAu7R5+CKoeKD3W LzLBh85Iak+UQhEgSAaVZV2IRLTrezTzEbk/x7T98hcAheP0UuwIXQEv7vWvo/JvqUhb +vlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TdY+gnjL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id pm10-20020a17090b3c4a00b0028513871956si5243401pjb.73.2023.11.20.11.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 11:18:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TdY+gnjL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5A7108037A9E; Mon, 20 Nov 2023 11:18:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjKTTSj (ORCPT + 99 others); Mon, 20 Nov 2023 14:18:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232525AbjKTTKm (ORCPT ); Mon, 20 Nov 2023 14:10:42 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DB06F9 for ; Mon, 20 Nov 2023 11:10:38 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ffb5a4f622so134890966b.0 for ; Mon, 20 Nov 2023 11:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700507437; x=1701112237; 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=m2uesSr1RZAG/avk1Qh8AUkPhBEOaB3euOWyklILHFo=; b=TdY+gnjLRFrp6ovIbujZESoLWWIu19mMJo7qQIsMen8NeJ5HKVfP/vvCWGO3TzDUsH eBQmUPzXriW2+yC5nBjmRiRDcjmpjVbefM+ry2/JJOaCURBpCUVc8qzIMzATGN/JYpR/ WsJF7ZY/1vH735csc1fcFpChEzu8Tt1u7kgBiN932M27iCc66i4AnzU2aC0h46r3Kd1n Q/tQzV6jR1Q6nTiwYeMOoxG+p4S4xHvkKhMHbWynCuEv22Sqf8yuH/b2Sn6SXWdU3Sjo Ul/hUwcUP+cHp/+3+g4E7QmuuL+sda2xo7uOsezvVW9+c2HqrftG6SxEo4Z87lWsLzSy Ax4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700507437; x=1701112237; 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=m2uesSr1RZAG/avk1Qh8AUkPhBEOaB3euOWyklILHFo=; b=k/D4oJCL5UPDS+GrWNLi8IjEiQk6EV/AE5OWbzGDvAScp9WX8e96ahnKtZ3V3MaHi4 AL5uw5Y91xTAJVdgnMPHqLXjSsqTDLkIzPy+t2lDB0tAFyZrUvOOmLMDCYAkyvBR9V58 D/TJxt46bKw6FS76k7RsqLGpG10jrlaju2drYQXLivL3zAX1LS2EB8vGl58EbMxO6auf Mp11AoFLV8w49lodzBj/U2Ua26lDAYMzINUXBIpnJ5TNwzpIIbDC84hhYgMlGL8itFnH bWy1V5WIL0cEgrL+iJxNY5aCMRT/fXKWuSv+jM3pf81ANisZueQr3/ml2idQBwsSkxsk Ub6w== X-Gm-Message-State: AOJu0Yx2iGZ3Etrn4GyoUffeGK7qiIciQ4PxpvOcpJPyB3XPqTlT8pIB 4aGILVCT49CGKvVywQOI03qC5ncvMX8tZIluZg29pQ== X-Received: by 2002:a17:906:5619:b0:9c4:b8c9:1bf4 with SMTP id f25-20020a170906561900b009c4b8c91bf4mr6269527ejq.19.1700507436601; Mon, 20 Nov 2023 11:10:36 -0800 (PST) MIME-Version: 1.0 References: <20231119194740.94101-1-ryncsn@gmail.com> In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> From: Yosry Ahmed Date: Mon, 20 Nov 2023 11:09:58 -0800 Message-ID: Subject: Re: [PATCH 00/24] Swapin path refactor for optimization and bugfix To: Kairui Song Cc: linux-mm@kvack.org, Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 20 Nov 2023 11:18:49 -0800 (PST) On Sun, Nov 19, 2023 at 11:48=E2=80=AFAM Kairui Song wro= te: > > From: Kairui Song > > This series tries to unify and clean up the swapin path, fixing a few > issues with optimizations: > > 1. Memcg leak issue: when a process that previously swapped out some > migrated to another cgroup, and the origianl cgroup is dead. If we > do a swapoff, swapped in pages will be accounted into the process > doing swapoff instead of the new cgroup. This will allow the process > to use more memory than expect easily. > > This can be easily reproduced by: > - Setup a swap. > - Create memory cgroup A, B and C. > - Spawn process P1 in cgroup A and make it swap out some pages. > - Move process P1 to memory cgroup B. > - Destroy cgroup A. > - Do a swapoff in cgroup C > - Swapped in pages is accounted into cgroup C. > > This patch will fix it make the swapped in pages accounted in cgroup B= . > I guess this only works for anonymous memory and not shmem, right? I think tying memcg charges to a process is not something we usually do. Charging the pages to the memcg of the faulting process if the previous owner is dead makes sense, it's essentially recharging the memory to the new owner. Swapoff is indeed a special case, since the faulting process is not the new owner, but an admin process or so. I am guessing charging to the new memcg of the previous owner might make sense in this case, but it is a change of behavior.