kmem.c 681 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "xfs.h"
  7. #include "xfs_message.h"
  8. #include "xfs_trace.h"
  9. void *
  10. kmem_alloc(size_t size, xfs_km_flags_t flags)
  11. {
  12. int retries = 0;
  13. gfp_t lflags = kmem_flags_convert(flags);
  14. void *ptr;
  15. trace_kmem_alloc(size, flags, _RET_IP_);
  16. do {
  17. ptr = kmalloc(size, lflags);
  18. if (ptr || (flags & KM_MAYFAIL))
  19. return ptr;
  20. if (!(++retries % 100))
  21. xfs_err(NULL,
  22. "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)",
  23. current->comm, current->pid,
  24. (unsigned int)size, __func__, lflags);
  25. memalloc_retry_wait(lflags);
  26. } while (1);
  27. }