@@ -612,168 +612,6 @@ unsigned long vm_mmap(struct file *file, unsigned long addr,
612
612
}
613
613
EXPORT_SYMBOL (vm_mmap );
614
614
615
- static gfp_t kmalloc_gfp_adjust (gfp_t flags , size_t size )
616
- {
617
- /*
618
- * We want to attempt a large physically contiguous block first because
619
- * it is less likely to fragment multiple larger blocks and therefore
620
- * contribute to a long term fragmentation less than vmalloc fallback.
621
- * However make sure that larger requests are not too disruptive - no
622
- * OOM killer and no allocation failure warnings as we have a fallback.
623
- */
624
- if (size > PAGE_SIZE ) {
625
- flags |= __GFP_NOWARN ;
626
-
627
- if (!(flags & __GFP_RETRY_MAYFAIL ))
628
- flags |= __GFP_NORETRY ;
629
-
630
- /* nofail semantic is implemented by the vmalloc fallback */
631
- flags &= ~__GFP_NOFAIL ;
632
- }
633
-
634
- return flags ;
635
- }
636
-
637
- /**
638
- * __kvmalloc_node - attempt to allocate physically contiguous memory, but upon
639
- * failure, fall back to non-contiguous (vmalloc) allocation.
640
- * @size: size of the request.
641
- * @b: which set of kmalloc buckets to allocate from.
642
- * @flags: gfp mask for the allocation - must be compatible (superset) with GFP_KERNEL.
643
- * @node: numa node to allocate from
644
- *
645
- * Uses kmalloc to get the memory but if the allocation fails then falls back
646
- * to the vmalloc allocator. Use kvfree for freeing the memory.
647
- *
648
- * GFP_NOWAIT and GFP_ATOMIC are not supported, neither is the __GFP_NORETRY modifier.
649
- * __GFP_RETRY_MAYFAIL is supported, and it should be used only if kmalloc is
650
- * preferable to the vmalloc fallback, due to visible performance drawbacks.
651
- *
652
- * Return: pointer to the allocated memory of %NULL in case of failure
653
- */
654
- void * __kvmalloc_node_noprof (DECL_BUCKET_PARAMS (size , b ), gfp_t flags , int node )
655
- {
656
- void * ret ;
657
-
658
- /*
659
- * It doesn't really make sense to fallback to vmalloc for sub page
660
- * requests
661
- */
662
- ret = __kmalloc_node_noprof (PASS_BUCKET_PARAMS (size , b ),
663
- kmalloc_gfp_adjust (flags , size ),
664
- node );
665
- if (ret || size <= PAGE_SIZE )
666
- return ret ;
667
-
668
- /* non-sleeping allocations are not supported by vmalloc */
669
- if (!gfpflags_allow_blocking (flags ))
670
- return NULL ;
671
-
672
- /* Don't even allow crazy sizes */
673
- if (unlikely (size > INT_MAX )) {
674
- WARN_ON_ONCE (!(flags & __GFP_NOWARN ));
675
- return NULL ;
676
- }
677
-
678
- /*
679
- * kvmalloc() can always use VM_ALLOW_HUGE_VMAP,
680
- * since the callers already cannot assume anything
681
- * about the resulting pointer, and cannot play
682
- * protection games.
683
- */
684
- return __vmalloc_node_range_noprof (size , 1 , VMALLOC_START , VMALLOC_END ,
685
- flags , PAGE_KERNEL , VM_ALLOW_HUGE_VMAP ,
686
- node , __builtin_return_address (0 ));
687
- }
688
- EXPORT_SYMBOL (__kvmalloc_node_noprof );
689
-
690
- /**
691
- * kvfree() - Free memory.
692
- * @addr: Pointer to allocated memory.
693
- *
694
- * kvfree frees memory allocated by any of vmalloc(), kmalloc() or kvmalloc().
695
- * It is slightly more efficient to use kfree() or vfree() if you are certain
696
- * that you know which one to use.
697
- *
698
- * Context: Either preemptible task context or not-NMI interrupt.
699
- */
700
- void kvfree (const void * addr )
701
- {
702
- if (is_vmalloc_addr (addr ))
703
- vfree (addr );
704
- else
705
- kfree (addr );
706
- }
707
- EXPORT_SYMBOL (kvfree );
708
-
709
- /**
710
- * kvfree_sensitive - Free a data object containing sensitive information.
711
- * @addr: address of the data object to be freed.
712
- * @len: length of the data object.
713
- *
714
- * Use the special memzero_explicit() function to clear the content of a
715
- * kvmalloc'ed object containing sensitive data to make sure that the
716
- * compiler won't optimize out the data clearing.
717
- */
718
- void kvfree_sensitive (const void * addr , size_t len )
719
- {
720
- if (likely (!ZERO_OR_NULL_PTR (addr ))) {
721
- memzero_explicit ((void * )addr , len );
722
- kvfree (addr );
723
- }
724
- }
725
- EXPORT_SYMBOL (kvfree_sensitive );
726
-
727
- /**
728
- * kvrealloc - reallocate memory; contents remain unchanged
729
- * @p: object to reallocate memory for
730
- * @size: the size to reallocate
731
- * @flags: the flags for the page level allocator
732
- *
733
- * If @p is %NULL, kvrealloc() behaves exactly like kvmalloc(). If @size is 0
734
- * and @p is not a %NULL pointer, the object pointed to is freed.
735
- *
736
- * If __GFP_ZERO logic is requested, callers must ensure that, starting with the
737
- * initial memory allocation, every subsequent call to this API for the same
738
- * memory allocation is flagged with __GFP_ZERO. Otherwise, it is possible that
739
- * __GFP_ZERO is not fully honored by this API.
740
- *
741
- * In any case, the contents of the object pointed to are preserved up to the
742
- * lesser of the new and old sizes.
743
- *
744
- * This function must not be called concurrently with itself or kvfree() for the
745
- * same memory allocation.
746
- *
747
- * Return: pointer to the allocated memory or %NULL in case of error
748
- */
749
- void * kvrealloc_noprof (const void * p , size_t size , gfp_t flags )
750
- {
751
- void * n ;
752
-
753
- if (is_vmalloc_addr (p ))
754
- return vrealloc_noprof (p , size , flags );
755
-
756
- n = krealloc_noprof (p , size , kmalloc_gfp_adjust (flags , size ));
757
- if (!n ) {
758
- /* We failed to krealloc(), fall back to kvmalloc(). */
759
- n = kvmalloc_noprof (size , flags );
760
- if (!n )
761
- return NULL ;
762
-
763
- if (p ) {
764
- /* We already know that `p` is not a vmalloc address. */
765
- kasan_disable_current ();
766
- memcpy (n , kasan_reset_tag (p ), ksize (p ));
767
- kasan_enable_current ();
768
-
769
- kfree (p );
770
- }
771
- }
772
-
773
- return n ;
774
- }
775
- EXPORT_SYMBOL (kvrealloc_noprof );
776
-
777
615
/**
778
616
* __vmalloc_array - allocate memory for a virtually contiguous array.
779
617
* @n: number of elements.
0 commit comments