From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 8CB03239E79 for ; Thu, 18 Dec 2025 07:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766042755; cv=none; b=TK1AQw1D9PjAcd8iWvlVk2OlbEC6NssHjmiUAuewHOs7ieMAqzUnJdPcOo1xFSZs/S7f2+GogPDXhKIf56f68TMVZn417SsWeq8gV2758pvr1+tXrs5wA9LFVdTt6q08GMP1I+yi3vRuw4yJolLGy1P3UbcV7TgWMFpkX5Xd+k4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766042755; c=relaxed/simple; bh=AxMH9y75DByNtx7wH1fMaghYsgpL8CMGuu42e3S7Bc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sK+G7CQ5Kfbx+wdow05ytC0Vtcfns0F2Q/g7deeQBipXvzDiglP/pWgG7mDWumomTN4GsktiqhUg86UeE8mFuIZfYSh81xeRQq8gHP3zcAj8aja/RymgXtlnGF1MgqlcpY1z9s0uqIuUccTSTAy1zLcWUh+k6CWpnKzVZLQJfvg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=So0nfZ3F; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="So0nfZ3F" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7bab7c997eeso450314b3a.0 for ; Wed, 17 Dec 2025 23:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766042753; x=1766647553; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q4R88Xn/h+8caxsc4FK/Mwtw22v+IgmOvKUTH+FxRso=; b=So0nfZ3FQbhyN8yaZvi+hlmt4YbM1sWVVG7i6dSVViFs5q1Oylf2IkD/czhf12DStb DpNx1CHYPUm+/B52SU0eEDDX/bxt8ILa+carl7tnFa3KTSnJUhV1aUcm0M03YiQuWEzU moU/luHoTKKSlaP/HDziD3TP2h8+f4Tgke20qIZ37lp4OkCb17vn99czCkLR9Xg/+uOr 7x6rhM2vVu+WyTfvVEIYzmp5D14Wrmj2fozPBcvsfxf3jz0Mm+Sl6aLXtkjQaz0aZTWe 9ZDsoWOtwNJ4OEVPDFU2qO+cpZ3gEh0uFNu+chFMyqKr3PzMIX/NizWuaGAnovebyTpm krXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766042753; x=1766647553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Q4R88Xn/h+8caxsc4FK/Mwtw22v+IgmOvKUTH+FxRso=; b=h0o2EgqNTjPaurw37Pnr5jiQPTdGBnDG9Kx1a1L7NmnMehSQXO9F196On7iU8er95L r4j00TwfN93b9iAzHlBNMOT//bGpkmWYWfjCqH3ICiHSQbNhcS9CFgmxBka7CNYuEfFA OQDscuehA6+0GUBCwpLKBm4w0zb11/8OwtWtqvzArvZ7l+zZuetTvNEa6umlw719jjc7 EhSAqV2TGjtGI4C71mAJglgH714vY5CRAtr3S3tQcpYipM1yI2uMSW+r1jGRpNM5CIVC qVKW8F3rJpNswyzKlw3FKu5OougOqbvLtkVnwq/gYSwauLixrDdm6VpjeV72dB2BhWGu JA/Q== X-Forwarded-Encrypted: i=1; AJvYcCWff/VfMUzWCIanYJ0HrUVV77qYPVaFgOICsZ7Oh+XpoJQabkzQrSX/pY226mBgzU1JVsMWjn90MfRaD9s=@vger.kernel.org X-Gm-Message-State: AOJu0YzRsN8+e/BYg0czHBiVjk2w17kdlCZGmmv1Mgcf/6nv8LMOIoks asF3dVzXpPerXmYjLE0McFM5tKg2XT7ICCC66FzW3bujnoWC4JV+Si44 X-Gm-Gg: AY/fxX43DN+tCbyYcuZpmCwc1P4xdVK/ew/+kHZ+BsuTbPyA1I12yhgGGZ8ySR/36A3 QFDM5hviIMvlYntjQyLiqZH8oLGV/Qx/shjQgPT3fzGVhSUso4iRZcfZ35YD+H2B+Nivw0V7Sad mhsNQqpkugIt7F+O4lMPddSBl4heitXYH+aYXT0HTqk9jkBAZ3oC+V2pygov9ZHo49b/MFJO3sc CTvkG+6fieIb/MjXYo0/KCY34v96yyGHyqj7+KB+T88SCnmjcMHtAOy0TExm/iSU3nbD54CHatS YVK3DwPekgUVc9+zmfv+omRiwdwFjSqYLR4E6jdVpiZh6hMCJGfHv+SyAvL/1kl/BO2UGtwNO5j W65OlTfzEFpBPF4aVs0K6b/CoEdZ+TtSiBJO86bMClGdQK0dgJs/2WSbR/znf/BE9XA42HuHsAC PZYQewLi3V X-Google-Smtp-Source: AGHT+IE7QD6jcxGZ721fK16jncezgZTI4shZ+xr6T/MCI8KS1Fg2nLGW1aiuenpQ0XBQS71PTipzjQ== X-Received: by 2002:a05:6a00:3499:b0:7e8:4471:ae68 with SMTP id d2e1a72fcca58-7f669a8e5bfmr19659120b3a.52.1766042752688; Wed, 17 Dec 2025 23:25:52 -0800 (PST) Received: from ubuntu.. ([103.163.65.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7fe1427026dsm1595735b3a.46.2025.12.17.23.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Dec 2025 23:25:52 -0800 (PST) From: Dipendra Khadka To: hannes@cmpxchg.org Cc: akpm@linux-foundation.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/memcg: reorder retry checks for clarity in try_charge_memcg Date: Thu, 18 Dec 2025 07:25:41 +0000 Message-ID: <20251218072543.5071-1-kdipendra88@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251215204624.GE905277@cmpxchg.org> References: <20251215204624.GE905277@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi Johannes, Thank you for the feedback. Let me clarify the scenario this patch addresses. The task_is_dying() check in try_charge_memcg() identifies when the CURRENT task (the caller) is the OOM victim - not when some other process was killed. Two scenarios: 1. Normal allocator triggers OOM: - Process A allocates → triggers OOM - Process B is killed (victim) - Process A continues with reset retries - task_is_dying() = false for A → Unchanged by my patch 2. Victim tries to allocate: - Process B (victim, TIF_MEMDIE set) tries to allocate - task_is_dying() = true - Current code: wastes retries on hopeless reclaims - My patch: exits immediately → Optimization for this case The victim has three safety mechanisms that make the retries unnecessary: 1. oom_reaper proactively frees its memory 2. __alloc_pages_slowpath() grants reserves via oom_reserves_allowed() 3. Critical allocations with __GFP_NOFAIL still reach force: label The retry loop for a dying victim is futile because: - Reclaim won't help (victim is being killed to free memory!) - Victim will exit regardless - Just wastes CPU cycles Would you like me to provide evidence showing the unnecessary retries, or run specific tests to verify the safety mechanisms are sufficient? Best Regards, Dipendra